UIButton有的時候需要用代碼做樣式調整 其中就包括添加陰影
如下圖 中登陸 按鈕
此時需要考慮對button的layer進行設置
button layer 設置以下幾個屬性
cornerRadius;
shadowOffset
shadowOpacity;
shadowColor;
代碼如下:
loginBtn=[UIButton buttonWithType:UIButtonTypeCustom]; loginBtn.frame=CGRectMake(10, 120, 88, 36); loginBtn.backgroundColor=[UIColor colorWithRed:44/255.0 green:178/255.0 blue:219/255.0 alpha:1.0]; loginBtn.layer.cornerRadius = 5; loginBtn.layer.shadowOffset = CGSizeMake(1, 1); loginBtn.layer.shadowOpacity = 0.8; loginBtn.layer.shadowColor = [UIColor blackColor].CGColor; [loginBtn setTitle:@"登 錄" forState:UIControlStateNormal]; [self.view addSubview:loginBtn];