Jason Renaldo
Jason Renaldo

Reputation: 2822

Restrict UIButton titleText frame

I have a custom UIButton that has some text I am setting on it dynamically.

The problem:

If the text gets too large, it will cover up a white arrow that is on the button's image located on the far right here:

enter image description here

When that text gets too large, that white arrow is covered, which I need to avoid.

Example:

enter image description here

Current code:

[self.filterButton setTitle:@"All" forState:UIControlStateNormal];
self.filterButton.titleLabel.adjustsFontSizeToFitWidth = YES;
self.filterButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;
self.filterButton.contentEdgeInsets = UIEdgeInsetsMake(0, 10, 0, 0);
[self.filterButton setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];

Some approaches I have tried:

Thanks for any guidance

Upvotes: 0

Views: 56

Answers (1)

Zack Brown
Zack Brown

Reputation: 6028

Have you tried setting the titleEdgeInsets rather than the contentEdgeInsets?

Upvotes: 1

Related Questions