1.设置按钮失效状态,即禁止点击该按钮(此时,界面显示该按钮为灰色,点击该按键失效)
@property (weak,nonatomic)IBOutletUIButton *testButton;
self.testButton.enabled=NO;
2.隐藏标签
@property (weak,nonatomic)IBOutletUILabel *sharkLb;
self.sharkLb.hidden =YES;
3.隐藏键盘--采用手势函数,点击空白处即可隐藏键盘,无需在xib文件添加任何连接
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
[self.byteTfresignFirstResponder]; //隐藏键盘
}
对于UITextField类,可以在利用代理--UITextFieldDelegate,实现点击Return或者Enter键,即可隐藏键盘:
self.myTf.delegate =self;
-(BOOL)textFieldShouldReturn:(UITextField *)textField{
[self.myTfresignFirstResponder];
return YES;
}
4.显示提示信息并要求用户确认--UIAlertView
UIAlertView *myview = [[UIAlertViewalloc]initWithTitle:@"Warning"
message:@"Password error.Please retype."
delegate:nil
cancelButtonTitle:@"OK"
otherButtonTitles:nil];
[myview show];
5.显示静态文本--UILabel
(1)多行文本自动换行
self.sharkLb.lineBreakMode =NSLineBreakByWordWrapping;//换行时单词保持在一起
self.sharkLb.numberOfLines = 0; //默认值为1,即使增加高度文本也不会换行
//根据文本内容设置文本行数numberOfLines,如果不知道标签内容需要几行才能显示,则设置为0
(2) 自动调整字体大小(仅适用于,显示1行文本的情况)
self.sharkLb.adjustsFontSizeToFitWidth =YES;
6. 设置UIButton的标题--setTitle[self.myBt setTitle:@"press me"forState:UIControlStateNormal]; //正常状态,按键标题为press me
[self.myBt setTitle:@"I'm pressed"forState:UIControlStateHighlighted]; //按下按键后,按键标题为I'm pressed
- (IBAction)onClickButton:(id)sender {
NSString *title = [sender titleForState:UIControlStateNormal];
}