IOS自定义UI组件的外观——使用UIAppearance协议自定义视图
align和valign有什么区别?
align 水平对齐方式
align=center或left或right
valign 垂直对齐方式
valign=top或middle或bottom
ios 设置一个textField不可编辑
(BOOL)textFieldShouldBeginEditing:(UITextField *)textField {
return NO;
}
从此不再担心键盘遮住输入框OC(二)
如何设置UILabel的内边距?
10个HTML5美化版复选框和单选框
UITextField 监听数值变化的三种方法 good
[self.textField1 addTarget:self action:@selector(textField1TextChange:) forControlEvents:UIControlEventEditingChanged];
iOS UIAppearance使用详解
- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. self.view.backgroundColor = [UIColor blackColor]; _upButton = [[UIButton alloc]init]; _downButton = [[UIButton alloc]init]; // [_upButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentLeft]; //ok [_upButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter]; // [_downButton setContentMode:UIViewContentModeBottomLeft]; //无效 [_downButton setContentHorizontalAlignment:UIControlContentHorizontalAlignmentRight]; _upButton.frame = CGRectMake(0, 20, 320, 40); _downButton.frame = CGRectMake(0, 60, 320, 25); [_upButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_downButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [_upButton setTitle:@"short" forState:UIControlStateNormal]; [_downButton setTitle:@"longlonglonglonglonglong" forState:UIControlStateNormal]; [self.view addSubview:_upButton]; [self.view addSubview:_downButton]; _textFieldA = [[UITextField alloc]init]; _textFieldB = [[UITextField alloc]init]; [_textFieldA setTextColor:[UIColor whiteColor]]; [_textFieldB setTextColor:[UIColor whiteColor]]; [_textFieldA setText:@"A"]; [_textFieldB setText:@"B"]; _textFieldA.textAlignment = UITextAlignmentCenter; //OK _textFieldB.textAlignment = UITextAlignmentRight; //OK _textFieldA.contentMode = UIViewContentModeCenter; //不行 /*不能居中*/ // _textFieldA.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //垂直居中 // _textFieldA.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; //水平居中 // // // _textFieldB.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter; //垂直居中 // _textFieldB.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter; //水平居中 _textFieldA.frame = CGRectMake(0, 85, 320, 40); _textFieldB.frame = CGRectMake(0, 125, 320, 25); [self.view addSubview:_textFieldA]; [self.view addSubview:_textFieldB]; _labelA = [[UILabel alloc]init]; _labelB = [[UILabel alloc]init]; [_labelA setTextColor:[UIColor whiteColor]]; [_labelB setTextColor:[UIColor whiteColor]]; [_labelA setText:@"A"]; [_labelB setText:@"B"]; _labelA.textAlignment = UITextAlignmentCenter; // ok _labelB.textAlignment = UITextAlignmentRight; // ok _labelA.frame = CGRectMake(0, 150, 320, 40); _labelB.frame = CGRectMake(0, 190, 320, 25); [self.view addSubview:_labelA]; [self.view addSubview:_labelB]; }
结果:
textview 不可编辑状态
_textview.editable = NO;
_textview.inputAccessoryView = nil;
UIButton 使用全面解析
UITextField 应用全面解析
//设置边框样式,只有设置了才会显示边框样式
text.borderStyle = UITextBorderStyleRoundedRect;
//输入框中是否有个叉号,在什么时候显示,用于一次性删除输入框中的内容
text.clearButtonMode = UITextFieldViewModeAlways;
//是否纠错
text.autocorrectionType = UITextAutocorrectionTypeNo;
/再次编辑就清空
text.clearsOnBeginEditing = YES;
//设置为YES时文本会自动缩小以适应文本窗口大小.默认是保持原来大小,而让长文本滚动
textFied.adjustsFontSizeToFitWidth = YES;
//首字母是否大写
text.autocapitalizationType = UITextAutocapitalizationTypeNone;
//return键变成什么键
text.returnKeyType =UIReturnKeyDone;
_mobileField.custfield.autocorrectionType = UITextAutocorrectionTypeNo;
autocorrectionType可以去掉键盘上面的一行提示文字