2017-11-08 5 views
1

次の方法を使用して、uitextfieldの特定の角を丸めます。ただし、角を丸くして境界線を消去する効果があります。誰もが境界を消去することなくこれを行う方法を提案することはできますか?事前に感謝の意を表します。IOS/Objective-C:境界線を削除せずに四角形の丸い角をつける

-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius { 
    CGRect rect = view.bounds; 
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect 
               byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight 
                cornerRadii:CGSizeMake(radius, radius)]; 
    CAShapeLayer *layers = [CAShapeLayer layer]; 
    layers.frame = rect; 
    layers.path = path.CGPath; 
    view.layer.mask = layers; 
} 

enter image description here

答えて

0

可能な方法の1つは、枠線を再描画することです。 As

-(void)roundBottomCornersOfView: (UITextField*) view by: (NSInteger) radius { 
    CGRect rect = view.bounds; 
    UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect 
         byRoundingCorners:UIRectCornerTopLeft |UIRectCornerTopRight 
         cornerRadii:CGSizeMake(radius, radius)]; 
    CAShapeLayer *layers = [CAShapeLayer layer]; 
    layers.frame = rect; 
    layers.path = path.CGPath; 
    view.layer.mask = layers; 

    CAShapeLayer* borderShape = [CAShapeLayer layer]; 
    borderShape.frame = self.imageView.bounds; 
    borderShape.path = path.CGPath; 
    borderShape.strokeColor = [UIColor blackColor].CGColor; 
    borderShape.fillColor = nil; 
    borderShape.lineWidth = 3; 
    [view.layer addSublayer:borderShape]; 
} 

希望します。 Referred from this SO Post

0

あなたはこれを試したことがありますか?その部分を達成するためにいくつかの角の半径を与えます。例:

nameOfTextField.layer.cornerRadius = 15.0 
nameOfTextField.layer.borderWidth = 2.0 // Use border width if you need it 
関連する問題