2016-11-22 7 views

ответ

0

В вас UICollectionViewCell's Подкласс

static CGFloat const kDashedBorderWidth  = (2.0f); 
static CGFloat const kDashedPhase   = (0.0f); 
static CGFloat const kDashedLinesLength[] = {4.0f, 2.0f}; 
static size_t const kDashedCount   = (2.0f); 



-(void)drawRect:(CGRect)rect 
{ 


    CGContextRef context = UIGraphicsGetCurrentContext(); 
    CGContextSetLineWidth(context, kDashedBorderWidth); 
    CGContextSetStrokeColorWithColor(context, [UIColor blackColor].CGColor); 
    CGContextSetLineDash(context, kDashedPhase, kDashedLinesLength, kDashedCount) ; 
    CGContextAddRect(context, rect); 
    CGContextStrokePath(context); 

} 
0

Добавить этот метод в своем классе.

- (CAShapeLayer *) addDashedBorderWithColor: (CGColorRef)color withSize:(CGSize)size{ 
    CAShapeLayer *shapeLayer = [CAShapeLayer layer]; 

    CGSize frameSize = size; 

    CGRect shapeRect = CGRectMake(0.0f, 0.0f, frameSize.width, frameSize.height); 
    [shapeLayer setBounds:shapeRect]; 
    [shapeLayer setPosition:CGPointMake(frameSize.width/2,frameSize.height/2)]; 

    [shapeLayer setFillColor:[[UIColor clearColor] CGColor]]; 
    [shapeLayer setStrokeColor:color]; 
    [shapeLayer setLineWidth:5.0f]; 
    [shapeLayer setLineJoin:kCALineJoinRound]; 
    [shapeLayer setLineDashPattern: 
    [NSArray arrayWithObjects:[NSNumber numberWithInt:10], 
     [NSNumber numberWithInt:5], 
     nil]]; 
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:shapeRect cornerRadius:15.0]; 
    [shapeLayer setPath:path.CGPath]; 

    return shapeLayer; 
} 

Напишите ниже код линии в вашем методе cellForRowAtIndexPath.

UICollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier"@"cell"]; 
    //Do what you want to set in your collectionViewCell 
    CAShapeLayer *maskLayer= [self addDashedBorderWithColor:[UIColor whiteColor].CGColor withSize:cell.borderView.frame.size]; 
    cell.layer.mask = maskLayer; 
+0

self.size контроллера точки зрения является ошибкой? –

+0

У меня нет какого-либо свойства в качестве пограничного вида в пользовательской ячейке, которую вы используете. –

+0

Я имею в виду изменить это с вашим собственным именем вида, на котором вы хотите нарисовать эту границу. Я только что пришлю вам мой объект dummuy. –