viewForFooterInSection

本文介绍如何在 UITableView 的 footer 中添加 UISwitch 和 UILabel,并调整其布局及交互属性,确保组件能正确显示并响应用户操作。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

http://stackoverflow.com/questions/838266/how-do-i-add-a-uibutton-or-uiswitch-in-tableviewviewforfooterinsection

 

// Need to refactor so that the label is Public Sharing and Priviate Sharing and the actions work for each switch

- ( UIView *) tableView : ( UITableView *) tableView
viewForFooterInSection
: ( NSInteger ) section
{
 
if ( section == 0 || section == 1 ) {
   
CGRect screenRect = [[ UIScreen mainScreen ] applicationFrame ];
   
UIView * footerView = [[ UIView alloc ] initWithFrame : CGRectMake ( 0 , 0 , screenRect . size . width , 44.0 )];
    footerView
. autoresizesSubviews = YES ;
    footerView
. autoresizingMask = UIViewAutoresizingFlexibleWidth ;
    footerView
. userInteractionEnabled = YES ;

    footerView
. hidden = NO ;
    footerView
. multipleTouchEnabled = NO ;
    footerView
. opaque = NO ;
    footerView
. contentMode = UIViewContentModeScaleToFill ;

   
// Add the label
   
UILabel *    footerLabel = [[ UILabel alloc ] initWithFrame : CGRectMake ( 150.0 , - 5.0 , 120.0 , 45.0 )];
    footerLabel
. backgroundColor = [ UIColor clearColor ];
    footerLabel
. opaque = NO ;
    footerLabel
. text = @ "Sharing" ;
    footerLabel
. textColor = [ UIColor tableHeaderAndFooterColor ];
    footerLabel
. highlightedTextColor = [ UIColor tableHeaderAndFooterColor ];
    footerLabel
. font = [ UIFont boldSystemFontOfSize : 17 ];
    footerLabel
. shadowColor = [ UIColor whiteColor ];
    footerLabel
. shadowOffset = CGSizeMake ( 0.0 , 1.0 );
   
[ footerView addSubview : footerLabel ];

   
[ footerLabel release ];  

   
// Add the switch
   
UISwitch * footerSwitch = [[ UISwitch alloc ] initWithFrame : CGRectMake ( 215.0 , 5 , 80.0 , 45.0 )];
   
[ footerView addSubview : footerSwitch ];

   
// Return the footerView
   
return footerView ;
 
}
 
else return nil ;
}
// Need to call to pad the footer height otherwise the footer collapses
- ( CGFloat ) tableView :( UITableView *) tableView heightForFooterInSection :( NSInteger ) section {
 
switch ( section ) {
   
case 0 :
     
return 40.0 ;
   
case 1 :
     
return 40.0 ;
   
default :
     
return 0.0 ;
 
}
}
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值