知识点总结:10-自定义第三方分享按钮

2017-01-26  本文已影响25人  枫之叶_小乙哥
#import "ZGKQuickLoginButton.h"

@implementation ZGKQuickLoginButton

/**** xib描述按钮=>awakeFromNib, 代码描述=>initWithFrame ****/

/**** 从xib中加载 ****/
- (void)awakeFromNib{
    [super awakeFromNib];
//    self.backgroundColor = [UIColor redColor];
//    self.imageView.backgroundColor = [UIColor redColor];
//    self.titleLabel.backgroundColor = [UIColor yellowColor];
// 设置文字格式
    self.titleLabel.textAlignment = NSTextAlignmentCenter;
}

/**** 重新设置frame ****/
- (void)layoutSubviews{
    [super layoutSubviews];
    
    // 1.修改图片的frame(修改y不是x,x在下面确定)
//    self.imageView.zgk_x = 0;
    self.imageView.zgk_y = 0;
    // 和上面的效果一样
//    self.imageView.frame = CGRectMake(0, 0, self.imageView.zgk_width, self.imageView.zgk_height);
    self.imageView.zgk_centerX = self.zgk_width * 0.5;

    // 2.修改文字的frame
    self.titleLabel.zgk_x = 0;
    
    /**** 高度和y值是不一样的 70.000000--15.000000 ****/
   // NSLog(@"%lf--%lf", self.imageView.zgk_height, self.imageView.zgk_y);
    
    // self.titleLabel.zgk_y = self.imageView.zgk_height;  因为imageView的y值不是0,而是15,这里应该是self.imageView.zgk_height = self.imageView.zgk_y
    self.titleLabel.zgk_y = self.imageView.zgk_y + self.imageView.zgk_height;
    self.titleLabel.zgk_width = self.zgk_width;
    self.titleLabel.zgk_height = self.zgk_height - self.imageView.zgk_height;
    
    // 和上面的效果一样
//    self.titleLabel.frame = CGRectMake(0, self.imageView.zgk_bottom, self.zgk_width, self.zgk_height - self.imageView.zgk_height);
}
上一篇 下一篇

猜你喜欢

热点阅读