我正在创建一个带有自定义图像的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];
图像显得伸展开来。我怎样才能使它正常适合?
谢谢!
答案 0 :(得分:0)
我所要做的只是添加:
[tempSpeedButton sizeToFit];