简体   繁体   中英

QuickDialog value too long for QLabelElement

Hi I have a QLabelElement and set the value for that like the following (same as in the sample app):

[s1 addElement:[[QLabelElement alloc] 
 initWithTitle:@"Long text long text long text long text" 
         Value:@"this is the value this is the value this is the value"]];

But now this element looks really ugly in the tableView cause obviously the text is too long:

在此处输入图片说明

how can I fix that? I am thinking about something like truncating the text or something but I have no idea where I can set that.

如果您要包装值文本,请查看我的找零

Ok it seams there is no easy way to solve my problem. The Solution is to costumize the QTableViewCell Class.

I rewrote it so the textlabel is the dominant one.

- (void)layoutSubviews {

    [super layoutSubviews];
    CGSize valueSize = CGSizeZero;

    if (self.textLabel.text!=nil)
        valueSize = [self.textLabel.text sizeWithFont:self.textLabel.font];


    CGSize imageSize = CGSizeZero;
    if (self.imageView!=nil)
        imageSize = self.imageView.frame.size;

    if (self.detailTextLabel.text ==nil) {
        CGRect labelFrame = self.textLabel.frame;
        self.textLabel.frame = CGRectMake(labelFrame.origin.x, labelFrame.origin.y,
                                          self.contentView.bounds.size.width - imageSize.width - 20, labelFrame.size.height);
        self.textLabel.backgroundColor = [UIColor   greenColor];
    }
    else{
        CGRect labelFrame = self.textLabel.frame;
        self.textLabel.frame = CGRectMake(labelFrame.origin.x, labelFrame.origin.y,
                                          valueSize.width, labelFrame.size.height);

    }




     CGRect detailsFrame = self.detailTextLabel.frame;
        self.detailTextLabel.frame = CGRectMake(self.textLabel.frame.origin.x + valueSize.width,
                                                detailsFrame.origin.y, self.contentView.bounds.size.width - valueSize.width - 
                                                imageSize.width - 20, detailsFrame.size.height);

}

If you have both long titles and long values then you can just add the following code to split den equally.

 if (valueSize.width > self.contentView.bounds.size.width/2) {
        valueSize.width = self.contentView.bounds.size.width/2;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM