如何更改UIToolbar高度?

时间:2016-08-22 08:20:37

标签: ios swift uitoolbar

我想在导航控制器中更改UIToolbar的高度,但是我无法在Xcode 7.3和iOS 9中快速更改。我试图在viewDidLoad中使用CGRectMake设置框架,但是它不起作用。还尝试初始化自定义UIToolbar(),但高度保持不变。

修改

根据其中一个答案,我尝试了选择的工具栏,按下控件并再次选择工具栏,但我得到的内容却显示在下面的屏幕截图中:

Screenshot

3 个答案:

答案 0 :(得分:5)

根据您是否使用故事板,有两个选项。

选项1:使用情节提要

1)转到故事板并从所选工具栏中按住Ctrl并再次单击工具栏,就像分配IBAction一样。然后你会得到以下内容:

(对不起第一张图片的质量;不得不用我的手机拍照,因为我无法在按住ctrl的同时制作截图)

enter image description here enter image description here

2)然后按高度以获得约束并更改值:

enter image description here

选项2:使用Swift进行处理55像素高度

 yourToolBar.frame = CGRect(x: 0, y: view.frame.size.height - 55, width: view.frame.size.width, height: 55)

答案 1 :(得分:2)

你可以用它; 将from kivy.app import App from kivy.config import Config from kivy.lang import Builder from kivy.graphics import Line from kivy.uix.screenmanager import ScreenManager, Screen from kivy.uix.widget import Widget from kivy.uix.image import Image from kivy.uix.floatlayout import FloatLayout from kivy.uix.behaviors import ButtonBehavior #Variables cords = () bld = Builder.load_file('conf.kv') class Manager(ScreenManager): pass class Principal(Screen): pass class ClickableImage(ButtonBehavior, Image): def on_press(self): self.source = 'button_press.png' def on_release(self): self.source = 'button.png' self.ids.uno.source = 'button_press.png' class canva(Widget): def on_touch_down(self, touch): global cords with self.canvas: touch.ud['line'] = Line(points=(touch.x, touch.y), width=1.5) cords = (touch.x, touch.y) def on_touch_move(self,touch): global cords touch.ud['line'].points = cords + (touch.x, touch.y) def on_touch_up(self,touch): self.canvas.clear() class Api(App): def build(self): return bld if __name__ == '__main__': Api().run() 更改为最小或最大高度。

# conf to file:  test.py

<Manager>:
    Principal:

<Principal>:
    GridLayout:
        size_hint_x: 0.5
        size_hint_y: 0.6
        width: self.minimum_width
        cols: 3
        ClickableImage:
            id: 'uno'
            size: 10,10
            source: 'button.png'
            allow_strech: True
        ClickableImage:
            id: 'dos'
            size: 30,30
            source: 'button.png'
            allow_strech: True
    canva:

与...一起使用

45

谢谢

答案 2 :(得分:0)

如果您使用自动布局,则可以在Storyboard中设置高度限制。

或者你可以这样编程:

myToolbar.frame = CGRectMake(0, 50, 320, 35)