Вы можете сделать это несколькими способами.
Способ 1. С просмотрами.
UIView *containerView = [[UIView alloc] initWithFrame:...];// The view that holds background, your label and lines
containerView.backgroundColor = [UIColor clearColor];
[containerView addSubView:bgImageView];
[containerView addSubView:label];
[label sizeToFit];
label.center = CGPointMake(containerView.frame.size.width/2, someY);
CGFloar margin = 5;
UIView *leftLineView = [UIView new];
leftLineView.backgroundColor = [UIColor whiteColor];
leftLineView.frame = CGRectMake(0, 0, containerView.frame.size.width - label.frame.size.width - margin, 0.5f);
leftLineView.center = CGPointMake(leftLineView.center.x, label.center.y);
UIView *rightLineView = [UIView new];
rightLineView.backgroundColor = [UIColor whiteColor];
rightLineView.frame = CGRectMake(label.frame.origin.x + label.frame.size.width + margin, 0, containerView.frame.size.width - label.frame.size.width - margin, 0.5f);
rightLineView.center = CGPointMake(rightLineView.center.x, label.center.y);
[containerView addSubiew:leftLineView];
[containerView addSubiew:rightLineView];
Способ 2. С помощью CoreGraphics.
Создайте собственный UIView и в методе -drawRect:
нарисуйте свои линии.
- (void)drawRect:(CGRect)rect
{
CGContextRef currentContext = UIGraphicsGetCurrentContext();
CGContextSetLineWidth(currentContext, 0.5f);
CGContextMoveToPoint(currentContext, 0.0f, self.label.center.y);
CGContextAddLineToPoint(currentContext, self.label.origin.x - margin , self.label.center.y);
CGContextMoveToPoint(currentContext, self.label.origin.x + self.label.frame.size.width + margin, self.label.center.y);
CGContextAddLineToPoint(currentContext, self.frame.size.width, self.label.center.y);
}
Что-то вроде этого :)
Обратите внимание, что я написал этот код непосредственно в редакторе SO, а не в Xcode, поэтому возможны некоторые синтаксические ошибки.
person
arturdev
schedule
04.12.2014