JLChen
2021-08-02 38f4fb064df09f344fc3237409c76a9fba2a8a9e
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
//
//  IASKPSTitleValueSpecifierViewCell.m
//  http://www.inappsettingskit.com
//
//  Copyright (c) 2010:
//  Luc Vandal, Edovia Inc., http://www.edovia.com
//  Ortwin Gentz, FutureTap GmbH, http://www.futuretap.com
//  All rights reserved.
// 
//  It is appreciated but not required that you give credit to Luc Vandal and Ortwin Gentz, 
//  as the original authors of this code. You can give credit in a blog post, a tweet or on 
//  a info page of your app. Also, the original authors appreciate letting them know if you use this code.
//
//  This code is licensed under the BSD license that is available at: http://www.opensource.org/licenses/bsd-license.php
//
 
#import "IASKPSTitleValueSpecifierViewCell.h"
#import "IASKSettingsReader.h"
 
 
@implementation IASKPSTitleValueSpecifierViewCell
 
- (void)layoutSubviews {
    [super layoutSubviews];
    
    CGSize viewSize =  [self.textLabel superview].frame.size;
 
    // if there's an image, make room for it
    CGFloat imageOffset = floor(self.imageView.image ? self.imageView.bounds.size.width + self.imageView.frame.origin.x : 0);
  
    // set the left title label frame
    CGFloat labelWidth = [self.textLabel sizeThatFits:CGSizeZero].width;
    CGFloat minValueWidth = (self.detailTextLabel.text.length) ? kIASKMinValueWidth + kIASKSpacing : 0;
    labelWidth = MIN(labelWidth, viewSize.width - minValueWidth - kIASKPaddingLeft -kIASKPaddingRight - imageOffset);
    CGRect labelFrame = CGRectMake(kIASKPaddingLeft + imageOffset, 0, labelWidth, viewSize.height);
    if (!self.detailTextLabel.text.length) {
        labelFrame = CGRectMake(kIASKPaddingLeft + imageOffset, 0, viewSize.width - kIASKPaddingLeft - kIASKPaddingRight - imageOffset, viewSize.height);
    }
    self.textLabel.frame = labelFrame;
    
    // set the right value label frame
    if (!self.textLabel.text.length) {
        viewSize =  [self.detailTextLabel superview].frame.size;
        self.detailTextLabel.frame = CGRectMake(kIASKPaddingLeft + imageOffset, 0, viewSize.width - kIASKPaddingLeft - kIASKPaddingRight - imageOffset, viewSize.height);
    } else if (self.detailTextLabel.textAlignment == NSTextAlignmentLeft) {
        CGRect valueFrame = self.detailTextLabel.frame;
        valueFrame.origin.x = labelFrame.origin.x + MAX(kIASKMinLabelWidth - imageOffset, labelWidth) + kIASKSpacing;
        valueFrame.size.width = self.detailTextLabel.superview.frame.size.width - valueFrame.origin.x - kIASKPaddingRight;
        self.detailTextLabel.frame = valueFrame;
    }
}
 
@end