Iphone 如何更改UIBarButtonItem图像大小
使用UIBarbuttonItem,initWithImage我得到了一张我想要的更小的图片 我觉得绝对没有办法调整图像的大小 UIedgeInsetMake根本不工作。调整picutre的大小也不起作用(像素化)。 我有一个@2x 48x48图标和一个普通的24x24。创建具有更大空边框的新图片不起作用 如果我使用20x20,它将像素化。不管怎样Iphone 如何更改UIBarButtonItem图像大小,iphone,objective-c,ios,uibarbuttonitem,uinavigationitem,Iphone,Objective C,Ios,Uibarbuttonitem,Uinavigationitem,使用UIBarbuttonItem,initWithImage我得到了一张我想要的更小的图片 我觉得绝对没有办法调整图像的大小 UIedgeInsetMake根本不工作。调整picutre的大小也不起作用(像素化)。 我有一个@2x 48x48图标和一个普通的24x24。创建具有更大空边框的新图片不起作用 如果我使用20x20,它将像素化。不管怎样 有解决办法吗?谢谢 如果要更改按钮的大小以匹配图像,最好创建UIButton并自定义UIBarButtonim。在UIBarButtonItem I
有解决办法吗?谢谢 如果要更改按钮的大小以匹配图像,最好创建UIButton并自定义UIBarButtonim。在UIBarButtonItem InitWithImages中,图像被缩放以适合UIBarButtonItem
观看anser以了解有关如何操作的更多信息。您可以使用自定义BarbuttonItem设置图像,并使用下面的方法调整标题大小:
+(UIBarButtonItem *)createToolBarButtonItemWithTitle:(NSString *)t target:(id)tgt action:(SEL)a
{
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
// Since the buttons can be any width we use a thin image with a stretchable center point
UIImage *buttonImage = [[UIImage imageNamed:@"toolbarbutton_button_mouseup.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
UIImage *buttonPressedImage = [[UIImage imageNamed:@"toolbarbutton_button_mouseover.png"] stretchableImageWithLeftCapWidth:5 topCapHeight:0];
[[button titleLabel] setFont:[UIFont boldSystemFontOfSize:12.0f]];
//[[button titleLabel] setFont:[UIFont fontWithName:@"Futura-Medium" size:12.0]];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
[button setTitleColor:[UIColor whiteColor] forState:UIControlStateHighlighted];
[[button titleLabel] setShadowOffset:CGSizeMake(0.0, 1.0)];
CGRect buttonFrame = [button frame];
buttonFrame.size.width = [t sizeWithFont:[UIFont boldSystemFontOfSize:12.0]].width + 24.0;
//Applicable only for iPhone FrameFun
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone && [[[NSUserDefaults standardUserDefaults] stringForKey:@"is_Landscape"] isEqualToString:@"landscape"]) {
buttonFrame.size.height = 23.0;
}else {
buttonFrame.size.height = buttonImage.size.height;
}
[button setFrame:buttonFrame];
[button setBackgroundImage:buttonImage forState:UIControlStateNormal];
[button setBackgroundImage:buttonPressedImage forState:UIControlStateHighlighted];
[button setTitle:t forState:UIControlStateNormal];
[button addTarget:tgt action:a forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem *buttonItem = [[UIBarButtonItem alloc] initWithCustomView:button];
return [buttonItem autorelease];
}
这个方法可以让你用想要的图像来制作按钮的动态尺寸。
这里我使用了
StretcableImageWithLeftCapWidth
来调整图像。我想这会对你有帮助。您也可以使用整个方法制作自定义按钮。这可以通过以下方法实现:
试一试…谢谢您的回答,但按钮大小很好,实际上非常完美。这是画在里面的图像,我想要更小的。代码不错,但这不是我想要的。我不想“画”一个自定义按钮。我想要一个经典的芭比娃娃,里面的图片比默认情况下画的要小一点。这对我来说非常合适。尤其对于.PDF图像非常有用