I know how to add border to a button in iOS 7, with the following code :
[[myButton layer] setBorderColor:[[[UIColor grayColor] colorWithAlphaComponent:0.5] CGColor]]; [[myButton layer] setBorderWidth:1]; [[myButton layer] setCornerRadius:15];
But how can I add just one border ? I want to add only the top border.
-- Basically just drop in a UIView in Interface Builder and change its class type to NAUIViewWithBorders. -- Then in your VC's viewDidLoad do something like: /* For a top border only ———————————————- */ self. myBorderView.
make your button Type - "Custom" and Uncheck - Highlighted Adjust image and you are done.
A control that executes your custom code in response to user interactions.
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, btn.frame.size.width, 1)]; lineView.backgroundColor = [UIColor redColor]; [btn addSubview:lineView];
you can do the same for each border. Adding multiple UIViews you can add bottom and left or top and right or any border you want.
i.e. bottom & left:
UIView *bottomBorder = [[UIView alloc] initWithFrame:CGRectMake(0, btn.frame.size.height - 1.0f, btn.frame.size.width, 1)]; bottomBorder.backgroundColor = [UIColor redColor]; UIView *leftBorder = [[UIView alloc] initWithFrame:CGRectMake(1, 0, 1, btn.frame.size.height)]; leftBorder.backgroundColor = [UIColor redColor]; [btn addSubview:bottomBorder]; [btn addSubview:leftBorder];
if you don't use ARC, remember to release UIViews after adding subviews (or use autorelease).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With