2016-06-21 3 views
0

私はプログラムでテーブルビューのセルをカスタマイズしました。iOSカスタマイズtableviewcell、セパレータの長さが間違っています

ヘッダファイル:

#import <UIKit/UIKit.h> 
@class LoadingCell; 

typedef NS_ENUM(NSUInteger, LoadingCellStyle) { 
    LoadingCellStyleSelection, 
    LoadingCellStyleTextField, 
    LoadingCellStyleImagePicker, 
}; 

@interface LoadingCell : UITableViewCell 

@property (nonatomic, strong) UIImageView* leftImageView; 
@property (nonatomic, strong) UILabel* titleLabel; 
@property (nonatomic, strong) UILabel* detailLabel; 

@property (nonatomic, assign) LoadingCellStyle style; 

-(instancetype)initWithStyle:(LoadingCellStyle)style; 

@end 

実装ファイル:ご覧のとおり

#import "LoadingCell.h" 

#define itemHeight 44 

@implementation LoadingCell 

-(instancetype)initWithStyle:(LoadingCellStyle)style 
{ 
    self = [super initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"loadingStats"]; 
    self.style = style; 

    [self.contentView addSubview:self.titleLabel]; 
    [self.contentView addSubview:self.leftImageView]; 

    if (self.style == LoadingCellStyleSelection) { 
    } 
    return self; 
} 

#pragma mark property setter 
-(UILabel *)titleLabel 
{ 
    if (!_titleLabel) { 
     _titleLabel = [[UILabel alloc] init]; 
     _titleLabel.textColor = COLOR_TEXT_GRAY; 
     _titleLabel.font = [UIFont systemFontOfSize:13]; 
    } 
    return _titleLabel; 
} 

-(UILabel *)detailLabel 
{ 
    if (!_detailLabel) { 
     _detailLabel = [[UILabel alloc] init]; 
     _detailLabel.textColor = COLOR_TEXT_GRAY; 
    } 
    return _detailLabel; 
} 

-(UIImageView *)leftImageView 
{ 
    if (!_leftImageView) { 
     _leftImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"star"]]; 
    } 
    return _leftImageView; 
} 

#pragma mark layouts 
-(void)layoutSubviews 
{ 
    CGRect imageframe = CGRectMake(k_Margin, 0, itemHeight, itemHeight); 
    [self.leftImageView setFrame:imageframe]; 
    [self.titleLabel setFrame:CGRectMake(CGRectGetMaxX(imageframe), 0, 100, itemHeight)]; 
    [self.detailLabel setFrame:CGRectMake(CGRectGetMaxX(self.titleLabel.frame), 0, kScreen_Width-CGRectGetMaxX(self.titleLabel.frame)-50, itemHeight)]; 
} 

@end 

そして結果は image

のように示され、電池セパレータは、右側に短いです。

self.separatorInset = UIEdgeInsetsMake(0, 0, 0, -100); 

このメソッドは回避できますが、私の方法では、tableviewセルをカスタマイズするのに間違いがあると思います。

はあなたに

答えて

0

ソリューションをありがとう:私は私のカスタマイズしたレイアウトメソッド内

[super layoutSubviews]; 

を逃しました。

関連する問題