这里我想在tabBarItem下面显示一行,如下图所示,我将按照以下方式设置它。然而问题是它是静态的,如果我使用更大的屏幕尺寸,如iPhone 6加上paintView2移动,看起来很难看。那么,如何为所有屏幕尺寸动态设置CGRectMake视图坐标。已经尝试过许多方法,但无法实现我想要的目标。
paintView2=[[UIView alloc]initWithFrame:CGRectMake(105,662,70, 5)];
NSLog(@"position:%f",paintView2.frame.origin.x);
CAGradientLayer *gradient = [CAGradientLayer layer];
gradient.colors = [NSArray arrayWithObjects:(id)[self colorWithHexString:@"34A9C4"].CGColor,(id)[self colorWithHexString:@"36AC60"].CGColor, nil];
gradient.frame = paintView2.bounds ;
[paintView2.layer insertSublayer:gradient atIndex:0];
[self.view addSubview:paintView2];
答案 0 :(得分:0)
在分配视图并给出框架时,您需要使其像
一样动态化CGRect screen = [[UIScreen mainScreen] bounds];
CGFloat ScreenWidth = CGRectGetWidth(screen);
CGFloat ScreenHeight = CGRectGetHeight(screen);
paintView2=[[UIView alloc]initWithFrame:CGRectMake((ScreenWidth/4)*i,ScreenHeight - 5, ScreenWidth/4, 5)];