關(guān)于Button
//設(shè)置圓角和顏色
業(yè)界對(duì)于圓角優(yōu)化很多方式,大家可以搜一下相關(guān)文章。本文只針對(duì)UILabel的cornerRadius方式進(jìn)行講解。
先說(shuō)一下cornerRadius屬性,它是影響layer顯示的backgroundColor和border,對(duì)layer的contents不起作用。
對(duì)于不需要設(shè)置label的backgroundColor,只設(shè)置borderWidth、borderColor的label,直接設(shè)置cornerRadius,不需要設(shè)置masksToBounds = YES,就可以實(shí)現(xiàn)圓角功能。
對(duì)于需要同時(shí)設(shè)置label的backgroundColor時(shí),直接設(shè)置cornerRadius是不能正常顯示圓角的,
原因是:UILabel設(shè)置backgroundColor的行為,不再是設(shè)定layer的背景色而是為contents設(shè)置背景色。所以解決方式是我們不去設(shè)置label的backgroundColor,而是直接設(shè)置label.layer.backgroundColor,這樣就可以實(shí)現(xiàn)單獨(dú)設(shè)置cornerRadius,顯示圓角的效果。
UILabel *tagLabel = [UILabel new];tagLabel.text = @"減";
tagLabel.textColor = [UIColor whiteColor];
tagLabel.font = [UIFont systemFontOfSize:12];
tagLabel.layer.backgroundColor = [UIColor greenColor].CGColor;
tagLabel.layer.cornerRadius = 2;
文字大小自適應(yīng)
1、確定Label或Button的字體大小,使其寬度自適應(yīng)
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的寬度,使字體大小自適應(yīng)
//無(wú)需自己設(shè)置字體大小
UILabel *contentLabel = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 120, 30)];
contentLabel.backgroundColor = [UIColor redColor];
contentLabel.text = @"我已知曉,且已閱讀并同意以上條款";
contentLabel.adjustsFontSizeToFitWidth = YES;//默認(rèn)為NO-------->注意和上面一句代碼順序不能顛倒
[self.View addSubview:contentLabel];
如果是Button的話(huà),和上面一樣,只有一點(diǎn)小小的區(qū)別:
[button.titleLabel sizeToFit];
button.titleLabel.adjustsFontSizeToFitWidth = YES;
常用的宏
#define KSCREEN_WIDTH [UIScreen mainScreen].bounds.size.width
#define KSCREEN_HEIGHT [UIScreen mainScreen].bounds.size.height
顏色的宏(隨機(jī)色和自定義顏色)
// 1.獲得RGB顏色
#define JMColor(r, g, b) [UIColor colorWithRed:(r)/255.0 green:(g)/255.0 blue:(b)/255.0 alpha:1.0]
//2.隨機(jī)色
#define RandomColor [UIColor colorWithRed:arc4random_uniform(256)/255.0 green:arc4random_uniform(256)/255.0 blue:arc4random_uniform(256)/255.0 alpha:1]
關(guān)于cell和tableView
//選中時(shí)沒(méi)有顏色效果
cell.selectionStyle=UITableViewCellSelectionStyleNone;
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath;
-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;
最后編輯于 :
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀(guān)點(diǎn),簡(jiǎn)書(shū)系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。