zoukankan      html  css  js  c++  java
  • iOS支持图文混排的按钮(UIButton)

    创建UIButton子类 直接上代码了 

    .h文件

    创建UIButton子类 直接上代码了 
    
    .h文件
    #import <UIKit/UIKit.h>
    
    @interface GraphicBtn : UIButton
    @property (nonatomic,assign)CGRect titleRect;
    @property (nonatomic,assign)CGRect imageRect;
    @end
    

     .m文件

     

    #import "GraphicBtn.h"

    @implementation GraphicBtn

    - (id)initWithFrame:(CGRect)frame

    {

        

        self = [super initWithFrame:frame];

        

        if (self) {

            

            //可根据自己的需要随意调整

            

    //        self.titleLabel.textAlignment = NSTextAlignmentCenter;

    //        

    //        self.titleLabel.font = [UIFont systemFontOfSize:12.0];

            

            self.imageView.contentMode = UIViewContentModeScaleToFill;

            

        }

        

        return self;

        

    }

    //重写父类UIButton的方法

    //更具button的rect设定并返回文本label的rect

    - (CGRect)titleRectForContentRect:(CGRect)contentRect

    {

        return self.titleRect;

    }

    //更具button的rect设定并返回UIImageView的rect

    - (CGRect)imageRectForContentRect:(CGRect)contentRect

    {

        return self.imageRect;

    }

    @end

    //  使用方法初始化按钮的时候自己计算好文字与图片的frame就可以了 

  • 相关阅读:
    设置圆角代码
    队列组的简单使用
    多线程的延时执行和一次性代码
    GCD线程间的通信
    GCD"牛逼的中枢调度器"
    线程间的通信
    KVO运行时
    iOS Programming Localization 本地化
    iOS Programming State Restoration 状态存储
    如何安装sql server2005 windows 8
  • 原文地址:https://www.cnblogs.com/weijie-1/p/5613375.html
Copyright © 2011-2022 走看看