Ios 在UIButton周围创建一个CAShapeLayer?
我有一个UIButton,我想在它的内容之外创建一个边框 我想用CAShapeLayer或其他合适的方法创建它 我怎么能这样做呢 UIButton的borderColor和BorderWidth属性在按钮内部创建边框。宽度越大,从内部消耗的空间越大Ios 在UIButton周围创建一个CAShapeLayer?,ios,objective-c,uibutton,cashapelayer,Ios,Objective C,Uibutton,Cashapelayer,我有一个UIButton,我想在它的内容之外创建一个边框 我想用CAShapeLayer或其他合适的方法创建它 我怎么能这样做呢 UIButton的borderColor和BorderWidth属性在按钮内部创建边框。宽度越大,从内部消耗的空间越大 谢谢。外面是什么意思?不能在远离按钮框的地方创建或添加任何内容。边框颜色/宽度在框架内完成,因此无法使其显示在远离框架的位置。 // This is the *.m file #import "ViewController.h" @interf
谢谢。外面是什么意思?不能在远离按钮框的地方创建或添加任何内容。边框颜色/宽度在框架内完成,因此无法使其显示在远离框架的位置。
// This is the *.m file
#import "ViewController.h"
@interface ViewController ()
// Comment A. Another label and button added to the class without adding them to the
// storyboard
@property (nonatomic, strong) UIButton *firstButton;
@end
@implementation ViewController
- (void)viewDidLoad
{
[super viewDidLoad];
self.firstButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[self.firstButton setTitle:@"Just a Button" forState:UIControlStateNormal];
self.firstButton.frame = CGRectMake(50, 50, 300, 40);
UIGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(theAction:)];
[self.firstButton addGestureRecognizer:tapGesture];
//The screen width and height
CGRect screenBound = [[UIScreen mainScreen] bounds];
CGSize screenSize = screenBound.size;
CGFloat screenWidth = screenSize.width;
CGFloat screenHeight = screenSize.height;
//The CALayer definition
CALayer *graphic = nil;
graphic = [CALayer layer];
graphic.bounds = CGRectMake(0, 0, screenHeight, screenWidth);
graphic.position = CGPointMake(screenHeight/2, screenWidth/2);
graphic.backgroundColor = [UIColor whiteColor].CGColor;
graphic.opacity = 1.0f;
[graphic addSublayer:self.firstButton.layer];
[self.view.layer addSublayer:graphic];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)theAction:(id)sender {
NSLog(@"Button Tapped");
}
@end