2016-10-08 43 views
1

我創建一個的UIBarButtonItem具有自定義圖像:如何使UIBarButtonItem NOT scaleToFit?

UIButton *tempSpeedButton = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, buttonWidth, buttonHeight)]; 
     UIImage *speedImage = [[UIImage imageNamed:@"eye"] imageWithRenderingMode:UIImageRenderingModeAlwaysTemplate]; 
     [tempSpeedButton setBackgroundImage:speedImage forState:UIControlStateNormal]; 
     [tempSpeedButton addTarget:self action:@selector(onSpeed) forControlEvents:UIControlEventTouchUpInside]; 
     tempSpeedButton.contentMode = UIViewContentModeScaleAspectFit; 
     UIBarButtonItem* speedButton = [[UIBarButtonItem alloc] initWithCustomView:tempSpeedButton]; 

圖像顯得捉襟見肘了。我怎樣才能使它適合正常?

謝謝!

回答

0

我所要做的就是補充一點:

[tempSpeedButton sizeToFit]