UITableViewCell Space between Title and Subtitle -iOS

后端 未结 5 1327
[愿得一人]
[愿得一人] 2021-01-12 16:22

How can I increase the space between the title and subtitle in UITableViewCell?

\"enter

相关标签:
5条回答
  • 2021-01-12 16:42

    The best way would be to just subclass UITableViewCell. That way, you can have total and complete control over the position of the labels. If this is not an option, you could modify each label's frame manually.

    0 讨论(0)
  • 2021-01-12 16:53

    You can add two labels in your cell content view instead of setting cell label. Adjust the y origin as per need. Adding heightForRowAtIndexPath will increase your cell height.

    0 讨论(0)
  • 2021-01-12 16:58

    subclass UITableViewCell to create a custom cell. Here is a great way to do this. It's simple and will also allow you future potential in making your cells look the way you want them to. The other nice thing about it is that each cell is generic, so you only have to create one customized class.

    0 讨论(0)
  • 2021-01-12 16:59

    If your row height is greater then the title and subtitle will be vertically middle align.

    - (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
    {
        return 100;
    }
    
    0 讨论(0)
  • 2021-01-12 17:03
    1. create a custom cell.
      1. new file->user interface-> empty
      2. name for your custom cell-> drag and drop a table view cell.
      3. now you have complete control. you can place your label anywhere.
      4. give a identifier name for your custom cell.
    2. create a class (subclass of UITableViewCell) for your custom cell.
      1. set property for your labels.
      2. synthesize property in .m
      3. make connection for your labels from IB.
    3. update your table view class.

      1. import custom cell's class.
      2. use your custom cell's identifier in cellForRowAtIndexPath.

        - (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
        {
            static NSString *simpleTableIdentifier = YOUR CUSTOM CELL's IDENTIFIER;
        
            SimpleTableCell *cell = (SimpleTableCell *)[tableView    dequeueReusableCellWithIdentifier:simpleTableIdentifier];
            if (cell == nil)
            {
                NSArray *nib = [[NSBundle mainBundle] loadNibNamed:@"SimpleTableCell" owner:self options:nil];
                cell = [nib objectAtIndex:0];
            }
        
        
            //configure your cell.
            cell.YOURLABEL1.text=@"YOUR TEXT FOR LABEL 1";
            cell.YOURLABEL2.text=@"YOUR TEXT FOR LABEL 2"
        
            return cell;
        }
        

    thats It.

    0 讨论(0)
提交回复
热议问题