将带有 UILabel 的 UIView 添加到现有视图
Add a UIView with a UILabel to an existing view
我在 UIView 中有一个日历,它位于我的 UIViewController 的顶部。当用户执行某些操作时,我想通过向下推 UIView(大约 50 像素)并插入另一个带有 UILabel 的 UIView 来在日历顶部显示一条小消息。这是我到目前为止的代码。更改约束后现有的 UIView 向下滑动,但新的 UIView 和 UILabel 不可见。
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
UILabel *labelInsert = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 100, 30)];
[labelInsert setText:@"Some Action Happened"];
[labelInsert setTextColor:[UIColor blackColor]];
UIView *viewInsert = [[UIView alloc] initWithFrame:frame];
[viewInsert setBackgroundColor:[UIColor greenColor]];
[viewInsert addSubview:labelInsert];
[self.view addSubview:viewInsert];
[self.constraintCalendarMenuViewTop setConstant:50];
难不成你的导航栏隐藏了插入的UIView?
另一种可能性可能是约束。评论最后一行能看到风景吗?
我在 UIView 中有一个日历,它位于我的 UIViewController 的顶部。当用户执行某些操作时,我想通过向下推 UIView(大约 50 像素)并插入另一个带有 UILabel 的 UIView 来在日历顶部显示一条小消息。这是我到目前为止的代码。更改约束后现有的 UIView 向下滑动,但新的 UIView 和 UILabel 不可见。
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, 50);
UILabel *labelInsert = [[UILabel alloc] initWithFrame:CGRectMake(0,0, 100, 30)];
[labelInsert setText:@"Some Action Happened"];
[labelInsert setTextColor:[UIColor blackColor]];
UIView *viewInsert = [[UIView alloc] initWithFrame:frame];
[viewInsert setBackgroundColor:[UIColor greenColor]];
[viewInsert addSubview:labelInsert];
[self.view addSubview:viewInsert];
[self.constraintCalendarMenuViewTop setConstant:50];
难不成你的导航栏隐藏了插入的UIView? 另一种可能性可能是约束。评论最后一行能看到风景吗?