我在不同的网页上有很多Labels
,TextView
和TextField
。如何编写一个方法来控制所有标签或textView的字体类型,字体大小,或检查6个文本字段是否为空?有办法吗?而不是像这样编写长代码
if ((txtfldFirst.text && txtfldFirst.text.length && txtfldLast.text && txtfldLast.text.length && txtfldPhone.text && txtfldPhone.text.length && txtfldEmail.text && txtfldEmail.text.length && txtViewComment.text && txtViewComment.text.length) )
[txt1 setFont:[UIFont fontWithName:@"GalaxiePolaris-Book" size:16.0]];
[txt2 setFont:[UIFont fontWithName:@"GalaxiePolaris-Book" size:16.0]];
[txt3 setFont:[UIFont fontWithName:@"GalaxiePolaris-Book" size:16.0]];
[txt4 setFont:[UIFont fontWithName:@"GalaxiePolaris-Book" size:16.0]];
...
.....
答案 0 :(得分:1)
创建一个子类。
New file -> iOS -> Source -> Cocoa Touch Class ->
-> MyLabel; subclass of UILabel
<。>在.m文件中写道:
- (instancetype)initWithFrame:(CGRect)frame {
if (self = super initWithFrame:frame]) {
self.font = [UIFont fontWithName:@"GalaxiePolaris-Book" size:16.0];
}
return self;
}
然后在您的控制器或视图中而不是
UILabel *label = [[UILabel alloc] initWithFrame:CGRectZero];
写:
MyLabel *label = [[MyLabel alloc] initWithFrame:CGRectZero];