How to add padding-left on a UILabel created programmatically?

前端 未结 8 1118
温柔的废话
温柔的废话 2020-12-29 06:33

I know this is a noob question but ...I have these labels on a tableview, but the text is completely squished to the left. I want to add a bit of padding. How do I go about

8条回答
  •  忘掉有多难
    2020-12-29 07:02

    You could use a UITextView instead. I did this in Cocoa but I'm pretty sure it translates to UITextView:

        NSTextView *headerLabel = [[[NSTextView alloc] initWithFrame:NSMakeRect(20.0, 20.0, 400.0, 20.0)] autorelease];
    [headerLabel setBackgroundColor: [NSColor redColor]];
    [headerLabel setString: @"Testing Stuff"];
    [headerLabel setTextColor:  [NSColor whiteColor]];
    
    NSSize txtPadding; 
    txtPadding.width = 20.0;
    txtPadding.height = 0.0;
    [headerLabel setTextContainerInset:txtPadding];
    
    [[mainWin contentView] addSubview:headerLabel];
    

提交回复
热议问题