iOS 4.3+ アプリケーション用のカスタム UIButtonを作成しました。背景画像を引き延ばしたかったので、次の方法を使用して背景画像を設定しました。
[myButton setBackgroundImage:[[UIImage imageNamed:myImagePath] stretchableImageWithLeftCapWidth:leftStretchValue topCapHeight:topStretchValue] forState:UIControlStateNormal]
[myButton setBackgroundImage:[[UIImage imageNamed:myHighlightedImagePath] stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateHighlighted]
[myButton setBackgroundImage:[[UIImage imageNamed:mySelectedImagePath]
stretchableImageWithLeftCapWidth:eftStretchValue topCapHeight:topStretchValue] forState:UIControlStateSelected]
カスタム ボタンにイベント ハンドラを追加しました
[myButton addTarget:self action:@selector(buttonHighlighted:) forControlEvents:UIControlEventTouchDown];
[myButton addTarget:self action:@selector(buttonSelected:) forControlEvents:UIControlEventTouchUpInside];
上記の方法では、それに応じてボタンの選択状態と強調表示状態を設定しました。UIButton のフレームを変更して、不規則な画像(mySelectedImage と myHighlightedImage、どちらも四角形ではありません)の寸法を調整して、myImageに合わせて適切に配置されるようにしました。
- (void) buttonSelected {
myButton.selected = !myButton.selected; //setting the selected property to NO in the viewDidLoad
//code to change the frame of the UIButton to accomodate the irregular image
}
- (void) buttonHighlighted {
myButton.highlighted = YES;
}
私が直面している問題は、myButton を選択すると、画像 myHighlightedImage と mySelectedImage が背景として表示される前に、myImage に灰色のオーバーレイが非常に短時間表示されることです。myButton の背景色を clearColor に設定しましたが、それが原因かもしれないと思っていますが、解決していません。
考えられる問題は何ですか...?