2

背景が透明な URL から画像を取得しようとしています。

しかし、NSData で使用しようとすると、代わりに黒い背景が表示されます。

UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
NSData *imgageURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"Image URL"]]; 
UIImage *image = [UIImage imageWithData:imageURL];

[button setImage:image forState:UIControlStateNormal];

ここのボタン画像では、透明ではなく黒の背景を取得しています。

URL から透明な画像を取得するにはどうすればよいですか?

4

3 に答える 3

0
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setBackgroundColor:[UIColor clearColor]];
NSData *imgageURL = [NSData dataWithContentsOfURL:[NSURL URLWithString:@"Image URL"]]; 
UIImage *image = [UIImage imageWithData:imageURL];
[button setImage:image forState:UIControlStateNormal];

背景色の問題だけがあります。

またはフォトショップで受信画像を開きます。

于 2012-05-21T14:08:48.310 に答える
0

setImage の代わりに setBackgroundImage:buttonImage を使用してみてください。

于 2012-05-21T13:15:31.177 に答える
0

まず、画像の背景が本当に透明かどうかを確認します (画像の URL を提供してください)。PNG画像ですか?

次に、ボタンのスーパービュー (およびスーパービュー) の背景の色を確認します。[UIColor clearColor]に設定できます。

それが役に立てば幸い

于 2012-05-21T13:12:17.543 に答える