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