Ios 在视图上显示自定义线
嗨,我想在视图中显示一条线,就像给定的图像一样 但当我这样做的时候,我会看到整个线路 我的代码-Ios 在视图上显示自定义线,ios,objective-c,Ios,Objective C,嗨,我想在视图中显示一条线,就像给定的图像一样 但当我这样做的时候,我会看到整个线路 我的代码- UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2,30, _MovetoSearch.frame.size.width, 1)]; lineView.backgroundColor = [UIColor whiteColor]; [_MovetoSearch addSubview:lineView]; 如何制作上图所示的线
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2,30, _MovetoSearch.frame.size.width, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
如何制作上图所示的线条?当您设置子图幅时,始终使用父图幅进行设置,因此,如果将来您可以更改父图幅,则无需更改子图幅,它将根据父图自动更改,如我所述
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(_MovetoSearch.frame.origin.x+2,_MovetoSearch.frame.size.height-5, _MovetoSearch.frame.size.width-30, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
我假设您的
searchBtn
也有类似的代码
UIButton *searchBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[searchBtn setFrame:CGRectMake(_MovetoSearch.frame.size.width-32, 0, 32, 32)];
[searchBtn setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateNormal];
[searchBtn setImage:[UIImage imageNamed:@"search.png"] forState:UIControlStateHighlighted];
[searchBtn addTarget:self action:@selector(searchBtnPressed) forControlEvents:UIControlEventTouchUpInside];
对于您的UITextField
应该是
CGFloat fieldHeight = searchBtn.frame.size.height-2;
CGFloat fieldWidth = _MovetoSearch.frame.size.width - (searchBtn.frame.size.width + 4);
UITextField *textfield = [[UITextField alloc] initWithFrame:CGRectMake(2, 0, fieldWidth, fieldHeight)];
[textfield setBackgroundColor:[UIColor clearColor]];
[textfield setBorderStyle:UITextBorderStyleNone];
[textfield setNeedsDisplay];
[_MovetoSearch addSubview:textfield];
用于线视图
CGFloat fieldHeight = searchBtn.frame.size.height-2;
CGFloat fieldWidth = _MovetoSearch.frame.size.width - (searchBtn.frame.size.width + 4);
UIView *lineView = [[UIView alloc] initWithFrame:CGRectMake(2, fieldHeight+1, fieldWidth, 1)];
lineView.backgroundColor = [UIColor whiteColor];
[_MovetoSearch addSubview:lineView];
希望它对您有用我建议您使用layer来完成这样的任务,不要过度使用UIView
CALayer * lineLayer = [CALayer alloc]init];
[lineLayer setFrame:CGRectMake(x,y,width,1)];
[lineLayer setBackgroundColor:[UIColor whiteColor].CGColor];
[self.view.layer addSublayer:lineLayer];
没有得到?你面临的问题是什么?“想在视图中显示一条线”,哪种视图?@Neon Samuel如何制作上述图像的线条什么是
\u MovetoSearch
,您是否在\u MovetoSearch
视图中包含搜索图标图像?@Sujay move ToSearch是uiviewhi的实例您能告诉我您的答案如何适合我的问题吗?您说的是不同的东西文本字段行和按钮,但我想要一行吗解开按钮或uiview并在图像中显示。如果你是对的,我怎么能使用你的代码呢?这只是一个设计,我只是想让ed通过action top其他视图。我想像上面一样设计