iOS中很多時候都需要用到指定風格的圓角按鈕,以下是UIButton
提供的創建圓角按鈕方法
設置按鈕的4個角:
左上:UIRectCornerTopLeft
左下:UIRectCornerBottomLeft
右上:UIRectCornerTopRight
右下:UIRectCornerBottomRight
示例代碼:
UIButton *button = [[UIButton alloc] initWithFrame:CGRectMake(50, 60, 80, 40)];button.backgroundColor = [UIColor orangeColor];[self.view addSubview:button]; //這里設置的是左上和左下角UIBezierPath *maskPath = [UIBezierPath bezierPathWithRoundedRect:button.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerTopLeft cornerRadii:CGSizeMake(8, 8)];CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];maskLayer.frame = button.bounds;maskLayer.path = maskPath.CGPath;button.layer.mask = maskLayer;
效果圖
總結
IOS設置按鈕為圓角的方法到這就結束了,大家都學會了嗎?希望這篇文章對大家的開發能有一定的幫助,如果有疑問大家可以留言交流。謝謝大家對武林網的支持。
新聞熱點
疑難解答