UIButton 設置圓角 邊框顏色 點擊回調方法

jopen 9年前發布 | 955 次閱讀 Objective-C IOS

UIButton *signBtn = [UIButton buttonWithType:UIButtonTypeCustom];

signBtn.frame = CGRectMake(0, 0, 80, 40);

[signBtn.layer setMasksToBounds:YES];

[signBtn.layer setCornerRadius:10.0]; //設置矩形四個圓角半徑

[signBtn.layer setBorderWidth:1.0]; //邊框寬度

CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();

CGColorRef colorref = CGColorCreate(colorSpace,(CGFloat[]){ 1, 0, 0, 1 });

[signBtn.layer setBorderColor:colorref];//邊框顏色

[signBtn setTitle:@"還 原" forState:UIControlStateNormal];//button title

[signBtn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];//title color

[signBtn addTarget:self action:@selector(buttonDonwRecover:) forControlEvents:UIControlEventTouchUpInside];//button 點擊回調方法

signBtn.backgroundColor = [UIColor whiteColor];

  • (void)buttonDonwRecover:(id)sender

{

UIButton *btn = (UIButton *)sender;

} </pre>

 本文由用戶 jopen 自行上傳分享,僅供網友學習交流。所有權歸原作者,若您的權利被侵害,請聯系管理員。
 轉載本站原創文章,請注明出處,并保留原始鏈接、圖片水印。
 本站是一個以用戶分享為主的開源技術平臺,歡迎各類分享!