gpt4 book ai didi

ios - 将 UILabel 粘贴到 UIView 或 UIImageView

转载 作者:行者123 更新时间:2023-11-28 23:10:31 25 4
gpt4 key购买 nike

我的应用程序中有一个包含 UIImageView 的 subview 。用户可以触摸这个 subview 并移动它。我有一些 UILabel,我想“粘贴”或与 subview 分组,以便它们随之移动。我想知道该怎么做?这是我将标签添加到 subview 的地方:

- (void)viewDidLoad
{
[super viewDidLoad];

//Decrease the site of root CALayer of the view and give it round corners
self.view.layer.backgroundColor = [UIColor orangeColor].CGColor;
self.view.layer.cornerRadius = 10.0;
self.view.layer.masksToBounds = YES;
self.view.layer.frame = CGRectInset(self.view.layer.frame, 40, 40);

//check if the background is from the photo library and create a sublayer for the semi transparent white badge and a textsublayer for the countdown labels. Also hide the regular view labels


NSString *path = [_occasion imagePath];

if (path != nil && [path hasPrefix:@"ass"])
{

//Make a subview with a UIImageView inside for the badge
CGRect badgeRect = CGRectMake(32, 13, 236, 222);
UIView *badge = [[UIView alloc] initWithFrame:badgeRect];
imageView = [[UIImageView alloc]initWithFrame:[badge frame]];

[imageView setImage:[UIImage imageNamed:@"badge.png"]];

[badge addSubview:imageView];

[self.view addSubview:badge];

/*[self.view bringSubviewToFront:countDownLabel];
[self.view bringSubviewToFront:daysLabel];
[self.view bringSubviewToFront:hoursLabel];
[self.view bringSubviewToFront:minutesLabel];
[self.view bringSubviewToFront:secondsLabel];
[self.view bringSubviewToFront:daysName];
[self.view bringSubviewToFront:hoursName];
[self.view bringSubviewToFront:minutesName];
[self.view bringSubviewToFront:secondsName];*/

[badge addSubview:countDownLabel];
[badge addSubview:daysLabel];
[badge addSubview:hoursLabel];
[badge addSubview:minutesLabel];
[badge addSubview:secondsLabel];
[badge addSubview:daysName];
[badge addSubview:hoursName];
[badge addSubview:minutesName];
[badge addSubview:secondsName];
//more code for recognizing the touches on the subview

最佳答案

只需将它们放在 UIImageView 上,它们就会随之移动。

关于ios - 将 UILabel 粘贴到 UIView 或 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8418044/

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