UIButton:
1、UIButton对于自定义Button需要设置宽度和高度才能显示,
2、而系统的Button在系统内部设置了宽度高度所以不需要认再去设置,如果人为改变其大小,显示的imageView大小是没有变化,只是Button的大小发生了改变
3、代码如下:
UIButton*button = [UIButton buttonWithType:UIButtonTypeContactAdd];
button.frame = CGRectMake(100, 100, 100, 100);
button.backgroundColor = [UIColor redColor];
[self.view addSubview:button];
NSLog(@"%@",NSStringFromCGRect(button.frame));
UILabel:
1、UILabel 需要设置宽度和高度才能显示
UILabel *lalel = [[UILabel alloc] initWithFrame:CGRectMake(100, 100, 100, 100)];
lalel.backgroundColor = [UIColor redColor];
[self.view addSubview:lalel];
NSLog(@"%@",NSStringFromCGRect(lalel.frame));
UIButton与UILabel详解
本文详细介绍了UIButton和UILabel的使用特点,特别关注自定义按钮时如何设置尺寸以确保正常显示,并对比了系统内置按钮的行为差异。此外,还通过代码示例展示了如何在视图中正确布置这些元素。
1429

被折叠的 条评论
为什么被折叠?



