3
我已经实现了一个自定义按钮,如下所示。如何在iPhone中根据它调整自定义按钮的大小文字
UIButton *mainBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[mainBtn setTitle:@"Meeting" forState:UIControlStateNormal];
[mainBtn setFrame:CGRectMake(80, 7, 72, 35)];
[mainBtn setBackgroundImage:[UIImage imageNamed:@"buttonActive.png"] forState:UIControlStateNormal];
mainBtn.contentEdgeInsets = UIEdgeInsetsMake(18, 5, 18, 10);
[mainBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
这里按钮标题将是动态的。所以现在我需要根据标题dynamicaly的长度来改变按钮的宽度。 CGRectMake与给定的宽度不会工作。有人能帮我做到吗?
这应该是诀窍... http://stackoverflow.com/a/4978003/716216 – 2012-03-05 11:05:02