我想在UIToolbar
上实现一个按钮,其中“图像”位于“顶部”和“文本”下方,如下所示。
我使用了以下代码:
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
但它显示的结果如下:
我应该如何以图像位于顶部和文本位于其下方的方式进行自定义?
我不想使用包含图片和文字的单个图片,因为文字是动态变化的。
答案 0 :(得分:1)
您需要设置边缘插入
customButton.titleEdgeInsets = UIEdgeInsetsMake(0, -60, -30, 0);
customButton.imageEdgeInsets = UIEdgeInsetsMake(-15, 0 , 0, 0); // give some space for text