如何制作UIBarButtonItem NOT scaleToFit?

时间:2016-10-08 17:02:39

标签: uibutton uiimage uibarbuttonitem

我正在创建一个带有自定义图像的UIBarButtonItem:

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];

图像显得伸展开来。我怎样才能使它正常适合?

谢谢!

1 个答案:

答案 0 :(得分:0)

我所要做的只是添加:

[tempSpeedButton sizeToFit];