- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我有 UIToolbar,我想给它添加相同大小的 UIButtons。目前,我有:
CGFloat width = self.toolbarMapMenu.frame.size.width / 4.0;
CGFloat height = self.toolbarMapMenu.frame.size.height;
btn0 = [self createMenuButton:@"a" width:width height:height];
btn1 = [self createMenuButton:@"b" width:width height:height];
btn2 = [self createMenuButton:@"c" width:width height:height];
btn3 = [self createMenuButton:@"d" width:width height:height];
UIBarButtonItem *it0 = [[UIBarButtonItem alloc] initWithCustomView:btn0];
UIBarButtonItem *it1 = [[UIBarButtonItem alloc] initWithCustomView:btn1];
UIBarButtonItem *it2 = [[UIBarButtonItem alloc] initWithCustomView:btn2];
UIBarButtonItem *it3 = [[UIBarButtonItem alloc] initWithCustomView:btn3];
[self.toolbarMapMenu setItems:[NSArray arrayWithObjects:
it0, it1, it2, it3,
nil]
];
还有别的地方
-(UIButton *)createMenuButton: (NSString *)name width:(CGFloat) w height:(CGFloat) h
{
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
btn.tintColor = [UIColor whiteColor];
[btn setImage:[UIImage imageNamed:name] forState:UIControlStateNormal];
[[btn.widthAnchor constraintEqualToConstant: w] setActive:true];
[[btn.heightAnchor constraintEqualToConstant: h] setActive:true];
btn.translatesAutoresizingMaskIntoConstraints = false;
return btn;
}
但是,当我添加这些按钮时,它们的大小相同,但第一个/最后一个按钮前后有一个间隙:
像这样的东西(UIToolbar):
(<gap> btn0 btn1 btn2 btn3 <gap>)
我怎样才能消除这个差距并从 toolbarMapMenu 的开头有按钮?
最佳答案
尝试在每个项目之间添加灵活的空间,它可能会解决您的问题并提供一致的 View 。
// Flexible Space
UIBarButtonItem *flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[self.toolbarMapMenu setItems:[NSArray arrayWithObjects:
it0, flexibleItem,
it1, flexibleItem,
it2, flexibleItem,
it3,
nil]];
关于ios - UIToolbar - 添加无间隙的等宽按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50047323/
我正在创建一个 UIToolbar,上面只放置了一个 UILabel。标签内容是动态的并且可以更改,我想将其集中在 UIToolbar 上。 有人知道 UIToolbar 左侧和右侧的确切边距大小吗?
我正在关注来自 here 的第二条提示.在本技巧中,两个 UIBarButtonItem 被放在一个 UIToolbar 中。最后,将 UIToolbar 添加到 UINavigationBar。现在
我有一个非常顽固的 UIToolbar,无论我尝试如何不同的方法,它都拒绝改变其高度。 我看过这个问题,但它对我不起作用 Is there a way to change the height of
如何制作垂直的 UIToolbar? 最佳答案 子类化 UIToolbar 并执行以下操作: CGFloat DegreesToRadian(CGFloat degrees) { return
是否可以在屏幕顶部放置一个 UIToolbar?示例应用程序类似于“日历”,右侧有“+”,左侧有“日历”按钮。 最佳答案 您可以将 UIToolbar 放置在任何地方。这只是一个 UI View 。
我需要创建一个使用图像作为背景的 UIToolbar 对象。大多数按钮也是图像,并且是矩形的。然而,有一个按钮是圆形的,并且与工具栏重叠,就像 Windows 任务栏上的“开始”按钮一样。见下文。 我
我想显示一个顶部有圆角的UIToolbar,最简单的方法是什么?工具栏未在窗口上对齐;它周围都有边距。谢谢! 最佳答案 非常简单。 首先 - 在 View Controller 的 .h 文件中有一个
我的 View 底部有一个 UIToolbar,并且此工具栏中有一个 UITextField。当我开始编辑此字段时,它隐藏在键盘后面。为了查看我输入的内容,我想在键盘出现时将工具栏向上移动(然后在完成
在我的应用程序中,我有一个工具栏,在某个时刻我想禁用或启用一些按钮。最简单的方法是什么?如何访问 UIToolbar 的 items 属性? 这是我的代码: -(void)addToolbar {
我有一个 UINavigationController,它被推送到 DetailsViewController。在这个DetailsViewController中,我想使用每个UINavigation
昨天下载了 IOS5 SDK,我用来将 UIToolbar 的背景设置为自定义图像的这段代码停止工作。如果我将目标设置为 IOS4.3 及以下,它仍然有效。 [self.bizToolbar inse
我正在尝试放置 UIToolBar在 UINavigationBar . UIToolbar* tempFontSizeToolBar = [[UIToolbar alloc] initWith
我有一个 UItableView,底部有一个工具栏。工具栏有两个按钮,分别是“水果”和“蔬菜”。单击它们将仅显示相应的类别。 我已经设法让显示功能正常工作,但我不知道如何在选择时将按钮设置为 sele
这个问题在这里已经有了答案: How to create this toolbar programmatically [closed] (6 个答案) 关闭 8 年前。 我试图在一个子类 ABPer
我想创建上面的用户界面。具体来说,一个更高的工具栏。但我需要以底层 UI(即内容 View )相应显示(即在工具栏下方)的方式这样做。 我熟悉 iOS 5 中新的 UIAppearance 选项。但是
UI问题在这里;我认为 UIToolbars 应该与状态栏融为一体?还是仅适用于 NavigationControllers? 最佳答案 UIToolBar 在顶部有一条默认的 1px 线(超出范围)
我有一个 UIToolbar。 如果我像这样创建一个 UIBarButton,它会起作用: UIBarButtonItem *button = [[UIBarButtonItem alloc] ini
我希望在用户单击按钮时(在我的例子中是当他们放大照片时)以编程方式将 UIToolbar 添加到 View 。 当我在 click 方法中创建工具栏并添加到 subview 时,它似乎工作正常但是如果
我的 View 上有一个 UITextView,并且可以通过按键盘工具栏上的完成按钮来关闭键盘。此按钮还对文本执行保存。在我的应用程序的最新版本之前,整个事情都运行得很好。我不明白发生了什么事。我怀疑
嘿伙计们,我正在尝试向 UIToolbar 添加文本,但有一个问题:我想更改字体并有 2 行文本(顶行较小,底行较大)。有什么想法如何做到这一点吗? 提前致谢! 最佳答案 您需要创建一个包含自定义 V
我是一名优秀的程序员,十分优秀!