0

RSS リーダーを含むアプリをプログラミングしています。RSS リーダーは、タイトル、説明、および画像をダウンロードしています。説明と同じセルのアクセサリビューに配置した画像。説明はテキストラベルに配置され、画像に合わせて完全にサイズ変更されます。しかし、画像を左側に表示したいと思います。しかし、accessoryview から画像を削除して左側の画像に移動すると、Textlabel のサイズは変更されません。

テキストラベルのサイズを変更するにはどうすればよいですか。

CGRect f = cell.textLabel.frame;
[cell.textLabel setFrame: CGRectMake(f.origin.x-20, f.origin.y, f.size.width-50, f.size.height)];

cell.textLabel.font = [UIFont systemFontOfSize:11];
cell.textLabel.numberOfLines =3;
cell.textLabel.textColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7];
cell.backgroundColor = [UIColor clearColor];
cell.textLabel.backgroundColor = [UIColor clearColor];
cell.selectionStyle = UITableViewCellSelectionStyleNone;

setframe 関数でサイズを変更しようとしましたが、うまくいきません。

私を正しい方向に押し進めることができる人がいることを願っています。

前もって感謝します

4

1 に答える 1

2

UITableViewCell クラスをサブクラス化する必要があります。次に例を示します。

.h ファイル:

#import <UIKit/UIKit.h>

@interface MyCustomerCell : UITableViewCell

@end

.m ファイル:

#import "MyCustomerCell.h"

@implementation MyCustomerCell

- (id)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier
{
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        // Initialization code
    }
    return self;
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated
{
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)layoutSubviews {
    [super layoutSubviews];
    self.imageView.frame = CGRectMake(0,0,150,90);
    self.imageView.bounds = CGRectMake(0, 0, 150, 90);
    self.textLabel.frame = CGRectMake(250, 0, 200, 40);   //change this to your needed
    self.detailTextLabel.frame = CGRectMake(250, 40, 200, 40);
}

@終わり

于 2012-05-05T17:50:35.463 に答える