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;
}
分享到:
相关推荐
这包括但不限于背景颜色、边框、圆角、字体、图标等。设计师通常会提供设计稿,开发者则需要根据设计稿进行实现。 2. **UIView**:自定义alertView通常基于UIView创建。首先,创建一个继承自UIView的类,并在此基础...
同时,为了方便复用,还可以提供一些公共方法,比如设置回调闭包来处理用户点击事件。 此外,为了方便在项目中引入这个自定义组件,我们可以将其打包成CocoaPods库或者Swift Package Manager包。这样,只需要在其他...
- 自定义提示框还需要处理用户的交互,例如点击按钮的回调。开发者可能在CustomAlertView中添加了手势识别器(如UIButton的touchUpInside事件),并定义了相应的处理方法。 6. **显示和隐藏**: - 显示和隐藏...
为了模拟标签的选中和未选中状态,我们可以设置`CAShapeLayer`的填充色或边框颜色。例如,当用户点击标签时,可以这样改变颜色: ```swift func handleTap(_ sender: UITapGestureRecognizer) { if selected { ...
设置`Timer`的属性,如边框宽度、圆角半径、字体和颜色等,并将其添加到视图上。对于按钮,设置其样式和事件监听器。 ```objc @implementation ViewController // 实现TimerDelegate协议 @interface ViewController...