UIActionSheet修改文字顏色

UIActionSheet是常用的控件之一,但往往需要再原來的基礎上修改一些小細節,這裏主要講解怎麼在iOS7以下和以上的處理方法。

-(void)willPresentActionSheet:(UIActionSheet *)actionSheet


{

    

    SEL selector = NSSelectorFromString(@"_alertController");

    

    if ([actionSheet respondsToSelector:selector])//ios8 以後採用UIAlertController來代替uiactionsheet和UIAlertView

        

    {

        

        UIAlertController *alertController = [actionSheet valueForKey:@"_alertController"];

        

        if ([alertController isKindOfClass:[UIAlertController class]])

            

        {

            

            alertController.view.tintColor = [UIColor blackColor];

            

        }

        

    }

    

    else//ios7 之前採用這樣的方式

        

    {

        

        for( UIView * subView in actionSheet.subviews )

            

        {

            

            if( [subView isKindOfClass:[UIButton class]] )

                

            {

                

                UIButton * btn = (UIButton*)subView;

                

                

                

                [btn setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];

                

            }

            

        }

        

    }

    

}


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章