小编Rob*_*usa的帖子

在swift中更改字体及其选择器的大小

使用Objective-C,我使用下面显示的代码来设置/更改选择器的字体系列和大小:

- (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
    tView.font = [UIFont fontWithName:@"Times New Roman" size:fontsize];;
}
tView.text = [_mysitedata findKeyForRow:row];
NSLog(@"C key:%@ row:%ld comp:%ld", tView.text, (long int)row, (long int)component);
return tView;
}
Run Code Online (Sandbox Code Playgroud)

但是,Swift不接受从UIView到UILabel的演员阵容,因此我不能遵循这条看起来如下所示的路径:

func pickerView(pickerView: UIPickerView, viewForRow row: Int, forComponent component: Int, reusingView view: UIView?) -> UIView {
    let label = view as! UILabel
    label.font = UIFont(name: "Times …
Run Code Online (Sandbox Code Playgroud)

picker uipickerview swift swift2

7
推荐指数
4
解决办法
2万
查看次数

标签 统计

picker ×1

swift ×1

swift2 ×1

uipickerview ×1