類似餓了么的定位titleView

就不寫實(shí)現(xiàn)原理,太簡單,給懶人的福利.

.h代碼

#import <UIKit/UIKit.h>

@interface WLlocationTitleView : UIView


@property(nonatomic, copy)NSString *addressText;

@end

.m代碼

#import "WLlocationTitleView.h"

@interface WLlocationTitleView ()

@property (nonatomic, strong)UIImageView *leftImageV;
@property (nonatomic, strong)UIImageView *rightImageV;
@property (nonatomic, strong)UILabel *textLabel;

@end


@implementation WLlocationTitleView

- (instancetype)initWithFrame:(CGRect)frame
{
    self = [super initWithFrame:frame];
    if (self) {
        
        _leftImageV = [[UIImageView alloc] init];
        _rightImageV = [[UIImageView alloc] init];
        _textLabel = [[UILabel alloc] init];
        
        
        [self addSubview:_leftImageV];
        [self addSubview:_rightImageV];
        [self addSubview:_textLabel];
        
        
        self.layer.masksToBounds = YES;
        self.layer.cornerRadius = frame.size.height / 2;
        
        [self setUI];
        
    }
    return self;
}


- (void)setUI
{
    _leftImageV.image = [UIImage imageNamed:@"position_icon"];
    [_leftImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(8);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.height.mas_equalTo(13);
        make.width.mas_equalTo(11);
    }];
    
    _textLabel.textColor = [UIColor whiteColor];
    _textLabel.font = [UIFont systemFontOfSize:14];
    _textLabel.text = @"定位中...";
    [_textLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(5);
        make.height.mas_equalTo(20);
        make.left.mas_equalTo(_leftImageV.mas_right).mas_offset(5);
    }];
    
    _rightImageV.image = [UIImage imageNamed:@"xiala_icon"];
    [_rightImageV mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.mas_equalTo(_textLabel.mas_right).mas_offset(5);
        make.centerY.mas_equalTo(self.mas_centerY);
        make.width.mas_equalTo(9);
        make.height.mas_equalTo(5);
    }];
    
}


-(void)setAddressText:(NSString *)addressText
{
    _addressText = addressText;
    _textLabel.text = _addressText;
    CGSize size = [WLTools textSizeWithContentSize:CGSizeMake(200, 20) font:[UIFont systemFontOfSize:14] str:_addressText];
    [_textLabel mas_updateConstraints:^(MASConstraintMaker *make) {
        make.width.mas_equalTo(size.width + 5);
    }];
}

調(diào)用時(shí),只需要傳入文本就好,圖標(biāo)自己換一下就好.

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

  • Android 自定義View的各種姿勢(shì)1 Activity的顯示之ViewRootImpl詳解 Activity...
    passiontim閱讀 179,029評(píng)論 25 709
  • 《我的少女時(shí)代》這部電影還沒上映之前就被里面那首主題曲《小幸運(yùn)》所吸引了。每次聽都會(huì)被歌詞的情緒所感染。其實(shí)歌詞...
    HANDKERCHIEF閱讀 313評(píng)論 0 0

友情鏈接更多精彩內(nèi)容