1. 程式人生 > >ios 開發 UIButton 新增圓角和陰影

ios 開發 UIButton 新增圓角和陰影

CALayer *layer = [CALayerlayer];

    layer.frame = CGRectMake(0,0 , 0.7*WIDTH, 40);

    layer.backgroundColor = kColor(244, 139, 100).CGColor;

    layer.shadowOffset = CGSizeMake(1, 10);

    layer.shadowOpacity = 0.7;

    layer.cornerRadius = 20;

    layer.shadowColor = kColor(244, 139, 100).CGColor;

//這裡self表示當前自定義的view

    [self.view.layeraddSublayer:layer];

UIButton * HomeButton = [[UIButtonalloc] initWithFrame:CGRectMake(0, , 0.7*WIDTH, 40)];

    [HomeButton setTitle:@"返回首頁" forState:UIControlStateNormal];

    HomeButton.backgroundColor = kColor(244, 139, 100);

    HomeButton.clipsToBounds = YES;

    HomeButton.layer.cornerRadius

= 20;

    [HomeButton addTarget:selfaction:@selector(back) forControlEvents:UIControlEventTouchUpInside];

    HomeButton.titleLabel.font = [UIFontsystemFontOfSize:15];

    [self.view addSubview:HomeButton];