【发布时间】:2014-05-17 02:26:50
【问题描述】:
我正在向我的导航栏添加一些自定义图像 UIBarButtonItems。如果我没有弄乱 item.width 属性,那么我的按钮靠得太近了,但是如果我用 width 属性将它们隔开,那么按钮图像就会变形。如何保持按钮图像的纵横比但将我的自定义项隔开?
// Create custom map button
UIButton *mapButton = [UIButton buttonWithType:UIButtonTypeCustom];
[mapButton setImage:[UIImage imageNamed:@"map.png"] forState:UIControlStateNormal];
[mapButton addTarget:self action:@selector(dismissMapView:) forControlEvents:UIControlEventTouchUpInside];
[mapButton setFrame:CGRectMake(280, 25, 30, 30)];
UIBarButtonItem *button1 = [[UIBarButtonItem alloc] initWithCustomView:mapButton];
button1.width = (self.drawer.frame.size.width / 5.0f); // Space it out a bit
// Create custom list button
UIButton *listButton = [UIButton buttonWithType:UIButtonTypeCustom];
[listButton setImage:[UIImage imageNamed:@"list.png"] forState:UIControlStateNormal];
[listButton addTarget:self action:@selector(scrollToRow:) forControlEvents:UIControlEventTouchUpInside];
[listButton setFrame:CGRectMake(280, 25, 30, 30)];
UIBarButtonItem *button2 = [[UIBarButtonItem alloc] initWithCustomView:listButton];
button2.width = (self.drawer.frame.size.width / 5.0f); // Space it out a bit
// Add buttons to drawer
self.drawer.items = @[button1,button2];
【问题讨论】:
-
设置 UIButton ImageEdgeInset .
标签: ios iphone objective-c