JHCategories
- 1. 从字符串设置视图的 Frame。
- 2. 一快速设置视图的属性的方法。
1. 从字符串设置视图的 Frame。
示例0: 开始。
UIView *view1 = [[UIView alloc] init];
//usually
view1.frame = CGRectMake(20,20,40,20);
//now
view1.frame = [self.view jhRectFromString:@"[x:20,y:20,w:40,h:20]"];
示例1: 设置视图的宽度为屏幕宽度的一半。
UIView *view1 = [[UIView alloc] init];
//usually
view1.frame = CGRectMake(0,20,self.view.frame.size.width/2,20);
//now
view1.frame = [self.view jhRectFromString:@"[x:0,y:20,w:2_w(0),h:30]"];
//self.view's tag is 0.
示例2: 将 view1 放置在 self.view 的中心。
//view1's width is 50,height is 50.
UIView *view1 = [[UIView alloc] init];
//usually
view1.frame = CGRectMake((self.view.frame.size.width - 50)/2,(self.view.frame.size.height - 50)/2,50,50);
//now
view1.frame = [self.view jhRectFromString:@"[x:2_w(0)-25,y:2_h(0)-25,w:50,h:50]"];
更多方法,找到你自己。
2.设置视图属性的快速方法。
示例0:视图。
UIView *view = [[UIView alloc] init];
//usually
view.frame = CGRectMake(20,40,50,30);
view.backgroundColor = [UIColor redColor];
view.layer.borderWidth = 2;
view.layer.borderColor = [UIColor blueColor].CGColor;
view.layer.cornerRadius = 5;
view.layer.masksToBounds = YES;
view.tag = 5;
//now
view
.jh_addToView(self.view)
.jh_frame(@"[x:20,y:40,w:50,h:30]")
.jh_bgColor([UIColor redColor])
.jh_bdWidth(@(2))
.jh_bdColor([UIColor blueColor])
.jh_cnRadius(@(5))
.jh_mtBounds(@(YES))
.jh_tag(@(5));
示例1:标签。
UILabel *label = [[UILabel alloc] init];
label
.jh_addToView(self.view)
.jh_frame(@[x:20,y:40,w:150,h:30]")
.jh_text(@"label")
.jh_color(@"0xa2s3f4")
.jh_font(@"s15")
.jh_bgColor(@"0xb1d10a")
.jh_align(@(1))
.jh_adjust(@(YES))
.jh_lines(@(0))
.jh_bdWidth(@(1))
.jh_bdColor([UIColor blueColor])
.jh_cnRadius(@(5))
.jh_mtBounds(@(YES))
.jh_tag(@(5));
示例2:按钮。
UIButton *button = [UIButton buttonWithType:UIButtonTypeSystem];
button
.jh_addToView(self.view)
.jh_frame(@"[x:20,y:80,w:150,h:30]")
.jh_title(@"button")
.jh_color(@"0x1a2b3c")
.jh_bgColor(@"0xa1b2c3")
.jh_cnRadius(@(5))
.jh_font(@"s17")
.jh_target_selector_event(self,@"jhButton",@(UIControlEventTouchUpInside));
注意:应在jh_frame之前调用jh_addToView。
- 更多支持:textField,textView,tableView,scrollView。
- 需要更多,请自己尝试。