gpt4 book ai didi

ios - UIToolbar UILabel x y 偏移不起作用

转载 作者:行者123 更新时间:2023-11-29 01:12:03 24 4
gpt4 key购买 nike

我遇到了一个奇怪的问题。我需要在 UIToolbar 中放置两个 UILabel。我有一个按钮,我想分享其中心的 UILabel,就好像我没有更改底部 UILabel 内 x 和 y 的值一样,它们不会移动。告诉我可能是什么问题。我需要将 UILabel 降低一点。

= [NSMutableArray new];
_createdLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 0, 100, 20)];
_createdLabel.backgroundColor = [UIColor clearColor];
_createdLabel.textColor = [UIColor whiteColor];
UIFont *myFont = [ UIFont fontWithName:@"GothamPro-Light" size:15.0f ];
_createdLabel.font = myFont;
_createdLabel.text = @"";
UIBarButtonItem *createdTitle = [[UIBarButtonItem alloc] initWithCustomView:_createdLabel];
[_items addObject:createdTitle];

UIBarButtonItem *space = [[UIBarButtonItem alloc]initWithBarButtonSystemItem: UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[_items addObject:space];

UILabel *shareLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, -1000, 85, 20)];
shareLabel.backgroundColor = [UIColor clearColor];
shareLabel.textColor = [UIColor whiteColor];
UIFont *shareFont = [ UIFont fontWithName:@"GothamPro-Light" size:15.0f ];
shareLabel.font = shareFont;
shareLabel.text = @"Поделиться";
[shareLabel sizeToFit];
UITapGestureRecognizer* tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(socialSharing:)];
[shareLabel setUserInteractionEnabled:YES];
[shareLabel addGestureRecognizer:tap];
UIBarButtonItem *shareTitle = [[UIBarButtonItem alloc] initWithCustomView:shareLabel] ;
[_items addObject:shareTitle];

UIBarButtonItem *shareBtn = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:@selector(socialSharing:)];
shareBtn.tintColor = [UIColor whiteColor];
[_items addObject:shareBtn];
[self.toolBar setItems:_items animated:YES];

enter image description here

最佳答案

请删除[shareLabel sizeToFit];在您的代码中。

使用以下代码作为共享标签。

    UILabel *shareLabel = [[UILabel alloc] initWithFrame: CGRectMake(0, 4, 85, 16)];

关于ios - UIToolbar UILabel x y 偏移不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/35623791/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com