UIPickerView - using custom views for multi-line rows - need layout advice

假如想象 提交于 2019-12-04 17:00:58

You need to set the frames and font of the two labels.

    v = [[[UIView alloc] init] autorelease];

    UILabel* l1 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 0, 320, 24)] autorelease];
    li.font = [UIFont sytemFontOfSize:22]; // choose desired size
    l1.tag = VIEWTAG_LINE1;
    [v addSubview: l1];

    UILabel* l2 = [[[UILabel alloc] initWithFrame:CGRectMake(0, 24, 320, 16)] autorelease];
    l2.font = [UIFont sytemFontOfSize:14]; // choose desired size
    l2.tag = VIEWTAG_LINE2;
    [v addSubview: l2];

Adjust the labels' height as needed. Adjust the y origin of l2 as needed.

If anyone's having this problem with Auto Layout, set translatesAutoresizingMaskIntoConstraints to YES (which is the default value). I was setting it to NO, which was causing all the problems.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!