首页 > 代码库 > iOS 用keypath设置一些属性

iOS 用keypath设置一些属性

1.UIButton title 距左边显

button.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;

  

  

2.UITextField placeholder 颜色

方法一:

textField.placeholder = @"this is placeholder";  
[textFieldsetValue:[UIColor redColor]forKeyPath:@"_placeholderLabel.textColor"];  
[textFieldsetValue:[UIFontboldSystemFontOfSize:16]forKeyPath:@"_placeholderLabel.font"]; 

  

方法二:(iOS 6 之后)

NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:@"this is placeholder"];

[placeholderaddAttribute:NSForegroundColorAttributeName
                  value:[UIColor redColor]
                  range:NSMakeRange(0, placeholder.length)];

[placeholderaddAttribute:NSFontAttributeName
                  value:[UIFontboldSystemFontOfSize:14]
                  range:NSMakeRange(0, placeholder.length)];


textField.attributedPlaceholder = placeholder;

 

3.隐藏 tabBar 顶部的分割线

[self.tabBar setValue:@(YES) forKeyPath:@"_hidesShadow"];

  

  

<style>p.p1 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #008400 } p.p2 { margin: 0.0px 0.0px 0.0px 0.0px; font: 11.0px Menlo; color: #3e1e81 } span.s1 { } span.s2 { font: 11.0px "PingFang SC" } span.s3 { color: #000000 } span.s4 { color: #ba2da2 } span.s5 { color: #703daa } span.s6 { color: #272ad8 } span.s7 { color: #d12f1b }</style>

iOS 用keypath设置一些属性