我有一个Viewcontroller,在其中设置了社交媒体的三个右侧Navbar按钮。以前,我在Xcode 8中运行应用程序。但是现在,当我将Xcode更新为9.1时,UI受到了干扰。导航栏会更改其宽度,现在会在整个导航栏中传播。该代码设置为宽度,但未按照代码运行。我的代码是这样的,
UIImage* image1 = [UIImage imageNamed:@"fab.png"];
CGRect frameimg1 = CGRectMake(3,0,30,30);
UIButton *someButton1 = [[UIButton alloc] initWithFrame:frameimg1];
[someButton1 setBackgroundImage:image1 forState:UIControlStateNormal];
[someButton1 addTarget:self action:@selector(facebook)
forControlEvents:UIControlEventTouchUpInside];
[someButton1 setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton1 =[[UIBarButtonItem alloc] initWithCustomView:someButton1];
UIImage* image2 = [UIImage imageNamed:@"tt.png"];
CGRect frameimg2 = CGRectMake(20,50,30,30);
UIButton *someButton2 = [[UIButton alloc] initWithFrame:frameimg2];
[someButton2 setBackgroundImage:image2 forState:UIControlStateNormal];
[someButton2 addTarget:self action:@selector(twitter)
forControlEvents:UIControlEventTouchUpInside];
[someButton2 setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton2 =[[UIBarButtonItem alloc] initWithCustomView:someButton2];
UIImage *image3 = [UIImage imageNamed:@"G+.png"];
CGRect frameimg3 = CGRectMake(0,30,30,30);
UIButton *someButton3 = [[UIButton alloc] initWithFrame:frameimg3];
[someButton3 setBackgroundImage:image3 forState:UIControlStateNormal];
[someButton3 addTarget:self action:@selector(gmail)
forControlEvents:UIControlEventTouchUpInside];
[someButton3 setShowsTouchWhenHighlighted:YES];
UIBarButtonItem *mailbutton3 =[[UIBarButtonItem alloc] initWithCustomView:someButton3];
[self.navigationItem setRightBarButtonItems:[NSArray arrayWithObjects:mailbutton1,mailbutton2,mailbutton3, nil]];
我认为在ios 11
barbuttonitems中无法使用框架。您必须设置必要的约束。这里的按钮宽度不合适,因此请尝试设置宽度,例如
[[someButton1.widthAnchor constraintEqualToConstant:30.0] setActive:YES];
[[someButton2.widthAnchor constraintEqualToConstant:30.0] setActive:YES];
[[someButton3.widthAnchor constraintEqualToConstant:30.0] setActive:YES];
为每个按钮设置宽度常数!
完成此操作后,如果遇到身高问题,请对heightAnchor
。
之所以发生这种情况,是因为您的图片必须比按钮的尺寸大,并且您没有给出高度和宽度的限制,因此需要调整按钮的尺寸来调整图片的尺寸!
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句