ios - 带有图像和动态文本的 UITool 栏按钮 "Below"it

标签 ios ipad ios7

我想在 UIToolbar 上实现一个按钮,“Image”位于顶部,文本位于其下方,如下所示。

enter image description here

我使用了以下代码:

UIButton* customButton = [UIButton buttonWithType:UIButtonTypeCustom];
[customButton setImage:[UIImage imageNamed:@"search2.png"] forState:UIControlStateNormal];
[customButton setTitle:@"Categorie" forState:UIControlStateNormal];
[customButton sizeToFit];
UIBarButtonItem* cataBtn = [[UIBarButtonItem alloc] initWithCustomView:customButton];initWithCustomView:customButton];
cataBtn 

但是显示结果如下:

enter image description here

我应该如何自定义它,使图像在上面,文本在它下面?

我不想用一个图片同时包含图片和文字,因为文字是动态变化的。

最佳答案

你需要设置边缘插入

customButton.titleEdgeInsets = UIEdgeInsetsMake(0, -60, -30, 0);
customButton.imageEdgeInsets = UIEdgeInsetsMake(-15, 0 , 0, 0); // give some space for text

关于ios - 带有图像和动态文本的 UITool 栏按钮 "Below"it,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23758702/

相关文章:

ios - Flurry AppSpot 测试广告未出现在设备上

ios - Firebase 和 iOS : FIRAuthInternalErrorDomain "MISSING_IDENTIFIER" when trying to login with custom token

ios - 如何制作适用于 IPAD 3 的 UIBlurEffect

ios - iOS7 是如何理解 Swift Code 的?操作系统是否支持 Swift?

iphone - 我可以创建没有颜色信息的顶点缓冲区对象吗?

iphone - 警告 : passing argument 1 of 'setOn:' makes integer from pointer without a cast

ios - 在 iPad 的系统键盘上添加自定义按钮可以吗

ios - 使用 ACcount 在 iOS 7 中集成 Flickr 和 Vimeo

ios - 使用 AsyncImageView 将图像加载到 ImageView 宽度

ios - iPhone-UITableView单元格标签颜色更改