您好,登錄后才能下訂單哦!
UIButton的基本用法,平時(shí)用的也就是這么多,其他遇到在加
//實(shí)例化2種方法
UIButton *btn1 = [[UIButton alloc] init];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
//坐標(biāo)和大小
btn.frame = CGRectMake(100, 100, 100, 100);
//背景顏色
btn.backgroundColor = [UIColor redColor];
//設(shè)置字體
[btn setTitle:@"UIButton" forState:UIControlStateNormal];
//設(shè)置字體顏色
[btn setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//設(shè)置層的弧度
btn.layer.cornerRadius = 50.0f;
//多余的層是否隱藏
btn.layer.masksToBounds = YES;
//設(shè)置層的寬度
btn.layer.borderWidth = 1.0f;
//設(shè)置層的顏色
btn.layer.borderColor = [[UIColor yellowColor]CGColor];
//標(biāo)記
btn.titleLabel.tag = 100;
//設(shè)置文字的大小
btn.titleLabel.font = [UIFont systemFontOfSize:12.0f];
//文字加粗
btn.titleLabel.font = [UIFont boldSystemFontOfSize:20];
//設(shè)置圖片
[btn setImage:[UIImage p_w_picpathNamed:@"1.png"] forState:UIControlStateNormal];
//設(shè)置背景圖片
[btn setBackgroundImage:[UIImage p_w_picpathNamed:@"1.png"] forState:UIControlStateNormal];
//設(shè)置透明度
[btn setAlpha:0.5f];
//是否選擇
[btn setSelected:YES];
//是否隱藏
[btn setHidden:NO];
//是否高亮
[btn setHighlighted:YES];
//是否可以觸摸
[btn setEnabled:YES];
//設(shè)置是否交互事
[btn setUserInteractionEnabled:YES];
//設(shè)置文字的偏移
[btn setTitleEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//設(shè)置圖片的偏移
[btn setImageEdgeInsets:UIEdgeInsetsMake(0, 0, 0, 0)];
//垂直
[btn setContentVerticalAlignment:UIControlContentVerticalAlignmentCenter];
//水平
[btn setContentHorizontalAlignment:UIControlContentHorizontalAlignmentCenter];
//文字居中
btn.titleLabel.textAlignment = NSTextAlignmentCenter;
//設(shè)置中心坐標(biāo)
[btn setCenter:CGPointMake(100, 100)];
//設(shè)置文字陰影顏色
[btn setTitleShadowColor:[UIColor grayColor] forState:UIControlStateNormal];
//文字發(fā)光
[btn setShowsTouchWhenHighlighted:YES];
//點(diǎn)擊事件
[btn addTarget:self action:@selector(goToView:) forControlEvents:UIControlEventTouchUpInside];
//加入視圖中
[self.view addSubview:btn];
免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場,如果涉及侵權(quán)請聯(lián)系站長郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。