搜尋

首頁  >  問答  >  主體

iOS 怎么把button的边缘变成虚线


比如这样

大家讲道理大家讲道理2771 天前446

全部回覆(2)我來回復

  • PHP中文网

    PHP中文网2017-04-18 09:45:21

    一個建議:一般這種情況,我們都是用圖片的,設定按鈕的背景圖片就好了。

    回覆
    0
  • 迷茫

    迷茫2017-04-18 09:45:21

    自訂一個Button吧

    @implementation CustomButton
    
    - (instancetype)initWithFrame:(CGRect)frame
    {
        self = [super initWithFrame:frame];
        if (self) {
            [self setupLayersWithFrame:frame];
        }
        return self;
    }
    
    - (void)setupLayersWithFrame:(CGRect)frame{
        CAShapeLayer * roundedrect = [CAShapeLayer layer];
        roundedrect.frame           = CGRectMake(0, 0, frame.size.width, frame.size.height);
        roundedrect.fillColor       = [UIColor whiteColor].CGColor;
        roundedrect.strokeColor     = [UIColor colorWithRed:0.329 green: 0.329 blue:0.329 alpha:1].CGColor;
        roundedrect.lineDashPattern = @[@5.5, @4.5];
        roundedrect.path            = [UIBezierPath bezierPathWithRoundedRect:CGRectMake(0, 0, frame.size.width , frame.size.height) cornerRadius:20].CGPath;
        [self.layer addSublayer:roundedrect];
    }
    

    回覆
    0
  • 取消回覆