我正在尝试在自定义键盘上创建一个按钮。这是我当前正在使用的代码:
CGRect ss = [[UIScreen mainScreen] bounds];
self.q = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.q setBackgroundImage:[UIImage imageNamed:@"back.png"] forState:UIControlStateNormal];
[self.q setTitle:@"Q" forState:UIControlStateNormal];
[self.q.titleLabel setTextColor:[UIColor whiteColor]];
self.q.titleLabel.font = [UIFont systemFontOfSize:30];
[self.q setFrame:CGRectMake(0*ss.size.width/10, 0, ss.size.width/10,self.view.bounds.size.height/4)];
[self.q addTarget:self action:@selector(size:) forControlEvents:UIControlEventTouchDown];
[self.view addSubview:self.q];
问题在于,当self.view.bounds.size.height应该返回0时,它应该返回键盘视图的高度。有一个与此类似的问题,但我尝试了答案,但没有一个起作用。
您应该将这些代码放在中viewDidLayoutSubviews
。
参考:https : //developer.apple.com/library/ios/documentation/UIKit/Reference/UIViewController_Class/index.html
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句