我有一個自定義的UIButton如下:的UIButton固定大小的自定義圖像
UIButton * action = [UIButton buttonWithType:UIButtonTypeCustom];
[action setSize:CGSizeMake(30, 30)];
[action setBackgroundImage:[UIImage imageNamed:@"contextaction.png"] forState:UIControlStateNormal];
[action setContentMode:UIViewContentModeCenter];
[action addTarget:self action:@selector(actionButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
,我有真正的圖像實際上是大小爲10×10,居中,我希望它保持下去,而不是縮放到按鈕大小。我怎麼做?
修改後的代碼:
UIButton * action = [UIButton buttonWithType:UIButtonTypeCustom];
[action setSize:CGSizeMake(44, 44)];
[action setImage:[UIImage imageNamed:@"contextaction.png"] forState:UIControlStateNormal];
[action addTarget:self action:@selector(actionButtonPressed:) forControlEvents:UIControlEventTouchUpInside];
if (IS_IPAD){
action.contentHorizontalAlignment = UIControlContentHorizontalAlignmentCenter;
action.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
}
actionButton_ = [[UIBarButtonItem alloc] initWithCustomView:action];
這仍然是縮放
我已經在用setImage,我怎麼設置contentHorizontalAlignment – adit 2012-03-14 23:01:53
它仍然是縮放到UIButton的大小改變 – adit 2012-03-14 23:15:28