【发布时间】:2014-04-21 04:06:08
【问题描述】:
我的 UIToolbar 中有一个按钮,我已为其分配了一个图像,但我希望图像自动按比例缩小(在应用程序外部调整图像大小会降低其质量)。
我尝试了解决方案here,它创建了一个自定义 imageView,然后将其分配给按钮。但是,图像似乎没有出现。这是我的代码:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"info.png"]];
imageView.frame = CGRectMake(0, 0, 35, 35);
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.userInteractionEnabled = YES;
UIBarButtonItem *barButtonItem = [[UIBarButtonItem alloc] initWithCustomView:imageView];
self.tutorial_lbl = barButtonItem;
请注意,如果我注释掉最后两行并改用下面的行,图像确实会出现,但随后会失去按钮的操作。
[self.tutorial_lbl setCustomView:imageView];
【问题讨论】:
标签: ios uiimage uibarbuttonitem uitoolbar