2016-11-04 17 views
0

x軸をタイトルヘッダーセクションに素早く変更する方法はありますか?私はそのコードを使用してそれを変更することはできませんよフレームをタイトルヘッダー(UITableView)に変更する方法

func tableView(tableView: UITableView, willDisplayHeaderView view: UIView, forSection section: Int) 
{ 
    let header:UITableViewHeaderFooterView = view as! UITableViewHeaderFooterView 
    header.textLabel!.textColor = UIColor.darkGrayColor() 
    header.textLabel!.font = UIFont(name: "Arial", size: 12.0)! 
    header.textLabel!.textAlignment = NSTextAlignment.Left 

    header.backgroundView?.backgroundColor = UIColor.sectionGray() 

    //Not working 
    header.textLabel!.frame.origin.x = header.textLabel!.frame.origin.x - 60 

} 
+0

なぜ 'viewForHeaderInSection'メソッドを使わないのですか? –

+0

フレームを変更する代わりに、トランスレートを使用してラベルを変換します。 – Adeel

答えて

1
header.textLabel!.frame = header.textLabel!.frame.offsetBy(dx: -60, dy: 0) 
+0

それは動作していません –

0
//Not working 
    header.textLabel!.frame.origin.x = header.textLabel!.frame.origin.x - 60 

あなたカントorign.xやorign.yを変更しないが、あなたは、フレームを変更または更新することができますフレーム

は1のUITableViewCellを作成し、あなたのストーリーボードにこのopproach

するのではなく、一つのことを行うとして、それを設計しますあなたがしたいと、これは客観的Cコードを迅速にそれを変換さSectionHeader

-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 


    SectionHeaderTableViewCell *headerView = [tableView dequeueReusableCellWithIdentifier:@"SectionHeader"]; 

    if (headerView == nil) { 
     headerView = (SectionHeaderTableViewCell*)[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:@"SectionHeader"]; 
    } 

    [email protected]"THIS WEEK"; 
     return headerView; 
} 

としてそのクラスとidntifireを定義し、これは例えばexithにヘッダーと

+0

私は@ mala_swiftを試してみてくださいそれを試してください –

+0

@マラ –

+0

私は必要なものではない –

0

使用ビューを再生するための最も簡単な方法です

enter image description here

#import "ViewController.h" 

@interface ViewController()<UITableViewDelegate,UITableViewDataSource> 
@property (strong, nonatomic) IBOutlet UIView *tableView; 
@property (strong, nonatomic) IBOutlet UITableView *myTable; 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
} 

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{ 
    return 10; 
} 
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{ 
    UITableViewCell *tblCell = [tableView dequeueReusableCellWithIdentifier:@"gm" forIndexPath:indexPath]; 
    return tblCell; 
} 
-(UIView *) tableView:(UITableView *)tableView viewForHeaderInSection:(NSInteger)section { 

    return self.tableView; 
} 
-(CGFloat)tableView:(UITableView *)tableView heightForHeaderInSection:(NSInteger)section{ 
    return 100; 
} 
- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

enter image description here

関連する問題