设置UIButton文本edgeInsets但现在文本不会响应触摸

时间:2014-03-14 00:22:52

标签: ios objective-c uibutton

我需要在我的UIButton中使用图片和文字,但在移动标题边缘时,文字是不可点击的?

 [self.tweetButton setImage: [UIImage imageNamed:@"shareTweet.png"] forState:UIControlStateNormal];
[self.tweetButton setTitleEdgeInsets:UIEdgeInsetsMake(7.0, 5.0, 5.0, -55.0)];
[self.tweetButton.titleLabel setFont:[UIFont fontWithName:@"GothamRounded-Light" size:18]];
[self.tweetButton addTarget:self
                    action:@selector(twitter:)
          forControlEvents:UIControlEventTouchUpInside];

1 个答案:

答案 0 :(得分:0)

我修好了。使按钮更长150px。然后做了这个。

 [self.tweetButton setImage: [UIImage imageNamed:@"shareTweet.png"] forState:UIControlStateNormal];
[self.tweetButton setTitleEdgeInsets:UIEdgeInsetsMake(7.0, 5.0, 5.0, -25.0)];
[self.tweetButton.titleLabel setFont:[UIFont fontWithName:@"GothamRounded-Light" size:18]];
[self.tweetButton addTarget:self
                     action:@selector(twitter:)
           forControlEvents:UIControlEventTouchUpInside];
self.tweetButton.contentHorizontalAlignment = UIControlContentHorizontalAlignmentLeft;