gpt4 book ai didi

ios - 按钮之间的标签在哪里

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

在下图中,我尝试在每个按钮之间放置一个单字符标签,但如第二张图所示,当我插入标签时,按钮会消失,并且(如果仔细观察)最后一个按钮的文本会移动向右。

你能帮我得到想要的结果吗?

没有标签的按钮 buttons without labels

带有标签的按钮 buttons with    labels

ViewController.h

@property(nonatomic,assign) UILabel* theSuit;

ViewController.m

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
NSString* cards = @"AKQJT98765432";

NSInteger yPipsOrigin = 100;
NSInteger xPipsOrigin = 100;
NSInteger xPipsStep = 40.0;
NSInteger xPipsCurrent = xPipsOrigin;
// Do any additional setup after loading the view.
for( int x=0;x<[cards length]; x++ ){
[cards substringWithRange:NSMakeRange(x,1)];
UIButton *b= [UIButton buttonWithType:UIButtonTypeRoundedRect];
xPipsCurrent += xPipsStep;
[b setTitle:[cards substringWithRange:NSMakeRange(x,1)] forState:UIControlStateNormal];
[b setTitle:@" " forState:UIControlStateDisabled];
[b setFrame:CGRectMake(xPipsCurrent, yPipsOrigin, 20, 20)];
[b setEnabled:YES];
[b setUserInteractionEnabled:YES];
[self.view addSubview:b];
[b addTarget:self action:@selector(spadeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

xPipsCurrent = xPipsOrigin + xPipsStep/2;
for( int x=0;x<[cards length]-1; x++ ){
xPipsCurrent += xPipsStep;
UILabel *lab = self.theSuit;
lab.text = @"Z";
lab.backgroundColor = [UIColor clearColor];
lab.center = CGPointMake(xPipsCurrent, yPipsOrigin);
[self.view addSubview:lab];
}
}

}

最佳答案

NSString* cards = @"AKQJT98765432";

NSInteger yPipsOrigin = 100;
NSInteger xPipsOrigin = 100;
NSInteger xPipsStep = 40.0;
NSInteger xPipsCurrent = xPipsOrigin;

for( int x=0;x<[cards length]; x++ )
{
[cards substringWithRange:NSMakeRange(x,1)];
UIButton *b= [UIButton buttonWithType:UIButtonTypeRoundedRect];
xPipsCurrent += xPipsStep;
[b setTitle:[cards substringWithRange:NSMakeRange(x,1)] forState:UIControlStateNormal];
[b setTitle:@" " forState:UIControlStateDisabled];
[b setFrame:CGRectMake(xPipsCurrent, yPipsOrigin, 20, 20)];
[b setEnabled:YES];
[b setUserInteractionEnabled:YES];
[self.view addSubview:b];
[b addTarget:self action:@selector(spadeButtonPressed:) forControlEvents:UIControlEventTouchUpInside];

UILabel *lab = [[UILabel alloc] initWithFrame:CGRectMake(xPipsCurrent+b.frame.size.width, yPipsOrigin, 20, 20)];
lab.text = @"Z";
lab.textAlignment = NSTextAlignmentCenter;
lab.backgroundColor = [UIColor clearColor];
[self.view addSubview:lab];
}

关于ios - 按钮之间的标签在哪里,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17167479/

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