UIButton custom angles angled with backlight?

I have the following code for a custom UIButton:

btnLogin.layer.cornerRadius = 10; [btnLogin setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"bluetint.png"]]]; [btnLogin setAlpha:1]; [btnLogin setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal]; [btnLogin setBackgroundImage:[UIImage imageNamed:@"reallybluetint.png"] forState:UIControlStateHighlighted]; [btnLogin setBackgroundImage:[UIImage imageNamed:@"reallybluetint.png"] forState:UIControlStateSelected]; 

When I select a button, it becomes square, even if it has rounded corners in the normal state.

Any ideas?

+4
source share
3 answers

Try with this code it will work,

 btnLogin.layer.cornerRadius = 10.0; [btnLogin setClipsToBounds:YES]; 
+6
source

I also had a similar problem, make sure that the button in the interface builder is set to user, because if it is not, you will see rounded corners.

Also, something useful that I found when working with images was UIEdgeInsets. Therefore, I could make such a special custom button.

 UIButton * customButton = [UIButton buttonWithType:UIButtonTypeCustom]; [customButton setBackgroundImage:[[UIImage imageNamed:@"customerImage.png"] resizableImageWithCapInsets:UIEdgeInsetsMake(1, 4, 2, 4)] forState:UIControlStateNormal]; 

But with any image you can use resizableImageWithCapInsets. I would recommend reading this to make sure that you can configure it correctly, but even if this does not help you understand that it may help you later.

Apple Doc Just Control F for Resizable

Hope this helps ^ _ ^

ps However, rounded corners will work if you try this and it doesn’t work, make sure you import Quartzcore. I often forget this step and become longing until I can understand it. Good luck anyway!

0
source

In Swift :

 import UIKit class CustomUIButtonForUIToolbar: UIButton { override func drawRect(rect: CGRect) { super.drawRect(rect) ... self.clipsToBounds = true } } 
0
source

All Articles