2017-02-01 2 views
-1

赤いボタンをプログラムで描画し、iOS6ボタン(勾配効果を含む)のルック&フィールを正確に表現しようとしています。プログラムでiOS 6のルックアライメントグラデーションを追加するUButton

私はiOS 6で自分のアプリケーションをサポートするためにこれをやっています。私はカスタムボタンで試しましたが、マイルストーンには到達できませんでした。クイックヘルプを感謝します。ここで

は「UITableViewCellの」クラス私は私のカスタムでやっていることです:

他人の利益のために
UIButton *myRedButton = [[UIButton alloc] initWithFrame:CGRectMake(CGRectGetMaxX(self.contentView.bounds) - 100, 0.0, 100, 35)]; 
myRedButton.titleLabel.font = [UIFont systemFontOfSize:12]; 
myRedButton.backgroundColor = [UIColor colorWithRed:194.0/255.0 green:21.0/255.0 blue:35.0/255.0 alpha:1.0]; 
myRedButton.layer.cornerRadius = 8.0; 
myRedButton.clipsToBounds = YES; 
[self.contentView addSubview:myRedButton]; 

enter image description here

+0

コードを投稿してくださいこれまでに達成したこと – redent84

+0

実際の質問はなぜですか? iOS 6の市場シェアは2%未満ですか? – CW0007007

+0

ええ、私は知っています。しかし残念なことに、私は私のアプリの1つのためにこれをサポートする必要があります。 – Abhinav

答えて

0

(場合にはいくつかのいずれかが同様の文脈を探しまわってされて)ここにどのように私はそれを達成しました:

UIButton *myRedButton = [[UIButton alloc] initWithFrame:autoReverseButtonFrame]; 
myRedButton.titleLabel.font = [UIFont boldSystemFontOfSize:14]; 
myRedButton.layer.cornerRadius = 8.0; 
myRedButton.clipsToBounds = YES; 
myRedButton.layer.borderColor = [UIColor blackColor].CGColor; 
self.autoReverseButton.layer.borderWidth = 1.0; 

CGColorRef topColor = [UIColor colorWithRed:240.0/255.0 green:127.0/255.0 blue:133.0/255.0 alpha:1.0].CGColor; 
CGColorRef bottomColor = [UIColor colorWithRed:194.0/255.0 green:21.0/255.0 blue:35.0/255.0 alpha:1.0].CGColor; 

CAGradientLayer *gradient = [CAGradientLayer layer]; 
gradient.frame = myRedButton.bounds; 
gradient.cornerRadius = myRedButton.layer.cornerRadius; 
gradient.colors = @[(__bridge id)topColor, (__bridge id)bottomColor]; 
[myRedButton.layer insertSublayer:gradient atIndex:0]; 
+0

グラデーションに白とアルファの組み合わせを使用すると、はるかに良いソリューションになり、ボタンの背景色を自由に変更できます。 – holex

関連する問題