Reputation: 147
I'm having a lot of difficulty trying to figure out how to make a UIButton look right. Essentially, it's supposed to look this this:
The UIButton is setup in a storyboard and has the appropriate constraints. Then, in the code I'm trying to customize it specifically for my use case. Here's the code from my method:
- (void)setupSkipBreakButton
{
NSString* buttonText = BMStringInApplicationLanguageForKey(skipIntroTextKey);;
[self.skipBreak setTitle: buttonText forState: UIControlStateNormal];
UIImage *skipBreak = [UIImage bm_imageWithBundlePath:BMVideoPlayerControlRackViewSkipBreakImageName];
[self.skipBreak setTitleEdgeInsets:UIEdgeInsetsMake(3.0, 1.0, 3.0, 0.0)];
[self.skipBreak setImageEdgeInsets:UIEdgeInsetsMake(3.0, 0.0, 3.0, 2.0)];
[self.skipBreak setImage:skipBreak forState:UIControlStateNormal];
self.skipBreak.backgroundColor = [[UIColor bm_colorWithHexString:BMVideoPlayerDefaultColor]
colorWithAlphaComponent:BMVideoPlayerDefaultAlpha];
[self.skipBreak addTarget:self action:@selector(skipBreakButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
}
Instead, the button actually has the 2 right arrows on the left side of "Skip Intro" when it should be on the right side as per the above image.
I don't see anything in my code that involves positioning the image as opposed to the text (other than the UIEdgeInsets?). So, I don't understand how to fix this issue.
Please help?
Upvotes: 0
Views: 45
Reputation: 5060
Here is code for doing what you want. Basically you need to check the value which you are passing in UIEdgeInsetsMake
.
UIImage *skipBreak = [UIImage imageNamed:@"testpic.png"];
[self.button setTitle:@"Tesst" forState:UIControlStateNormal];
[self.button setTitleEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, 30.0)];
[self.button setImage:skipBreak forState:UIControlStateNormal];
[self.button setImageEdgeInsets:UIEdgeInsetsMake(0.0, 0.0, 0.0, -57)];
[self.button setBackgroundColor:[UIColor yellowColor]];
which result is below:
I would suggest if you still not able to set the image the best and easy way to use the storyboard.
Step:
Now use these options and play with them. Best way to learn.
Upvotes: 1