こんにちは、UIPickerview 行にテキストを表示しています。しかし、ラベルのサイズが大きすぎると、ピッカー行が表示されます... ラベルの最後に。
これではなく、ピッカーの行にタイトル全体を表示したい。ピッカービューでタイトルの幅に合わせてフォント サイズを自動的に設定できますか。
こんにちは、UIPickerview 行にテキストを表示しています。しかし、ラベルのサイズが大きすぎると、ピッカー行が表示されます... ラベルの最後に。
これではなく、ピッカーの行にタイトル全体を表示したい。ピッカービューでタイトルの幅に合わせてフォント サイズを自動的に設定できますか。
次のメソッドを実装する必要があります。
- (UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
UILabel* tView = (UILabel*)view;
if (!tView){
tView = [[UILabel alloc] init];
// Setup label properties - frame, font, colors etc
...
}
// Fill the label text here
...
return tView;
}
コントローラーを UIPickerViewDelegate と UIPickerViewDataSource にすると、このルーチンを使用して、ピッカー行に必要なカスタム変更を加えることができます。
-(UIView *)pickerView:(UIPickerView *)pickerView viewForRow:(NSInteger)row forComponent:(NSInteger)component reusingView:(UIView *)view{
//make your own view here, it can be a UILabel if you want, or other kind of view.
//You can give it any size font you need.
}