您现在的位置是:主页 > news > 网站建设80hoe/国际购物网站平台有哪些
网站建设80hoe/国际购物网站平台有哪些
admin2025/4/29 1:21:50【news】
简介网站建设80hoe,国际购物网站平台有哪些,wordpress电源解析插件,网站建设与运营 教材 崔1.在设置button的属性时,用titleLabe设置不起作用,UIButton继承于UIControl,需要设置状态, 按钮中得label的frame默认是(0,0,0,0);hidden 的属性默认是YES; 2.button中的图片文字排列:默认时图片在左,文字在右 注意:设置按钮文字的状态不能…
1.在设置button的属性时,用titleLabe设置不起作用,UIButton继承于UIControl,需要设置状态,
按钮中得label的frame默认是(0,0,0,0);hidden 的属性默认是YES;
2.button中的图片文字排列:默认时图片在左,文字在右
注意:设置按钮文字的状态不能用UIControlStateHighLighted否则控制台会报警告 可以用选中状态的UIControlStateSelected
// 实例化一个button
UIButton *headerButton = [[UIButtonalloc]init];
/**
设置背景图片
设置图片的时候,哪些一定要分状态
title/titleColor , image , backgroudImage
button.titleLabel.font // 所有状态下的文本大小
*/
[btn setTitle:@"按钮"forState:UIControlStateNormal];
[btn setTitleColor:[UIColorredColor]forState:UIControlStateNormal];
//设置按钮的图片时,UIControlStateHighlighted就相当于点击按钮时;
[headerButton setBackgroundImage:[UIImageimageNamed:@"buddy_header_bg"]forState:UIControlStateNormal];
[headerButton setBackgroundImage:[UIImageimageNamed:@"buddy_header_bg_highlighted"]
forState:UIControlStateHighlighted];
// 设置图片
[headerButton setImage:[UIImageimageNamed:@"buddy_header_arrow"]forState:UIControlStateNormal];
// 给title 设置颜色
[headerButton setTitleColor:[UIColorblackColor]
forState:UIControlStateNormal];
// 设置button的水平对其方式
headerButton.contentHorizontalAlignment =UIControlContentHorizontalAlignmentLeft;
[self.collectBtnsetContentHorizontalAlignment:
UIControlContentHorizontalAlignmentLeft];//设置水平方向的位置居左
[self.collectBtnsetContentVerticalAlignment:
UIControlContentVerticalAlignmentTop];//设置竖直方向的位置居上
//返回label的size大小
CGSize ttitleSize = [self.collectBtn.titleLabel.text sizeWithAttributes:@{ NSFontAttributeName : [UIFont fontWithName:@"HelveticaNeue-Light" size:10] }];
// 设置图片的内边距
headerButton.imageEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
// 设置文本的内边距
headerButton.titleEdgeInsets = UIEdgeInsetsMake(0, 15, 0, 0);
/**
保证button的imageView在旋转之后保持原有的形状
UIViewContentModeScaleToFill, 拉伸填充
UIViewContentModeScaleAspectFit, 自适应
UIViewContentModeScaleAspectFill, 自适应填充
UIViewContentModeCenter, 保持原有的尺寸
*/
headerButton.imageView.contentMode =UIViewContentModeCenter;
// clipsToBounds = YES; 超出父view的边界的部分将会被剪切掉
headerButton.imageView.clipsToBounds =NO;
3. //为按钮添加点击事件
[headerButton addTarget:self
action:@selector(didLClickButton:)
forControlEvents:UIControlEventTouchUpInside];
4. //获取按钮图片和标题
UIImage *image = [btn backgroundImageForState:
UIControlStateHighlighted];//获取高亮状态下的图片;
UIImage *img=btn.currentImage;//获取当前按钮的图片;
NSString *str =[btn titleForState:UIControlStateNormal];//获取正常状态下的按钮标题
//取消失效状态的按钮图像调整
self.adjustsImageWhenDisabled =NO;
// 取消高亮状态的按钮图像调整
self.adjustsImageWhenHighlighted =NO;
5.=======按钮中的点击事件:
通知所有事件。
6.=============吧按钮放到最顶层
[self.view bringSubviewToFront:self.cameraBtn];
7。=================按钮标题自适应大小
*********1、确定Label或Button的字体大小,使其宽度自适应
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
contentLabel.font = [UIFont systemFontOfSize:15];//-------->定义Font的大小
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.text = @"我已知晓,且已阅读并同意以上条款";
[contentLabel sizeToFit];//-------->字体大小固定,宽度自适应
[self.View addSubview:contentLabel];
************2、确定Label或Button的宽度,使字体大小自适应
//无需自己设置字体大小
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.text = @"我已知晓,且已阅读并同意以上条款";
contentLabel.adjustsFontSizeToFitWidth = YES;//宽度固定,字体大小自适应
[self.View addSubview:contentLabel];
***********如果是Button的话,和上面一样,只有一点小小的区别:
[button.titleLabel sizeToFit];
button.titleLabel.adjustsFontSizeToFitWidth = YES;