所以我在导航栏中创建了一个按钮,并为其设置了一个图像。 这就是故事板中的样子: http : //imgur.com/cSRfHs3
所以我试图将它设置在屏幕边缘,这样图像和屏幕左侧之间就没有间隙了。
这是我用过的代码:
var screenWidth: CGFloat=0.0 var screenHeight: CGFloat=0.0 @IBOutlet weak var button1: override func viewDidLoad() { super.viewDidLoad() UIButton! var screenSize: CGRect = UIScreen.mainScreen().bounds screenWidth = screenSize.width screenHeight = screenSize.height button1.frame.size = CGSizeMake(133, 44) button1.frame.origin = CGPoint(x: screenWidth-(button1.frame.width+20), y: 20) self.view.addSubview(button1)这是结果: http : //imgur.com/HZqxnqr
这是因为我将我的按钮直接添加到TableView吗?
So I've created a button in the navigation bar and set an image for it. This is how it looks like in storyboard: http://imgur.com/cSRfHs3
So I've tried to set it right on the edge of the screen so there will be no gap between the image and the left side of the screen.
Here is the code I've used for it:
var screenWidth: CGFloat=0.0 var screenHeight: CGFloat=0.0 @IBOutlet weak var button1: override func viewDidLoad() { super.viewDidLoad() UIButton! var screenSize: CGRect = UIScreen.mainScreen().bounds screenWidth = screenSize.width screenHeight = screenSize.height button1.frame.size = CGSizeMake(133, 44) button1.frame.origin = CGPoint(x: screenWidth-(button1.frame.width+20), y: 20) self.view.addSubview(button1)And here is the result: http://imgur.com/HZqxnqr
Is this happening because I add my button straight to the TableView?
最满意答案
您需要将按钮直接放在导航栏中。 您还可以使用xcode storyboard gui为按钮添加约束。
You need to place the button directly in the navbar. Also you can add constraints to your button using the xcode storyboard gui.
更多推荐
发布评论