ios 自訂訊息提示框,ios自訂訊息

來源:互聯網
上載者:User

ios 自訂訊息提示框,ios自訂訊息

自訂提示框,3秒鐘後自動消失。如顯示效果。

提示框載入代碼:

- (void)viewDidLoad {    [super viewDidLoad];        //將view背景顏色變更為黃色    self.view.backgroundColor = [UIColor yellowColor];        //在self.view上載入提示框    [[BIDNoteView sharedInstance] showNoteView:@"顯示提示資訊" subView:self.view];}

BIDNoteView.h 代碼:

////  BIDNoteView.h//  label上畫橫線////  Created by eJiupi on 14-7-23.//  Copyright (c) 2014年 xujinzhong. All rights reserved.//#import <Foundation/Foundation.h>@interface BIDNoteView : NSObject+ (BIDNoteView*)sharedInstance;- (void)showNoteView:(NSString*)noteText subView:(UIView*)subView;-(void)setFont:(UIFont*)font;@end

BIDNoteView.m 實現代碼:

////  BIDNoteView.m//  label上畫橫線////  Created by eJiupi on 14-7-23.//  Copyright (c) 2014年 xujinzhong. All rights reserved.//#import "BIDNoteView.h"@interface BIDNoteView ()//@property (strong, nonatomic) UIView *subView;@property (strong, nonatomic) UIView *noteView;@property (strong, nonatomic) UILabel *noteLable;@property (strong, nonatomic) NSTimer *timer;@end@implementation BIDNoteView+ (BIDNoteView*)sharedInstance{    static BIDNoteView* instance = nil;    if (instance == nil)    {        instance = [[BIDNoteView alloc] init];    }    return instance;}- (id)init{    self = [super init];    if (self)    {        NSInteger w = 220;        NSInteger h = 50;        NSInteger x = ([UIScreen mainScreen].bounds.size.width-w)/2;        NSInteger y = [UIScreen mainScreen].bounds.size.height-60-h;               self.noteView = [[UIView alloc] initWithFrame:CGRectMake(x, y, w, h)];        self.noteView.layer.cornerRadius = 5.0;        self.noteView.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.6];                self.noteLable = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, w, h)];        self.noteLable.text = @"親,沒有更多商品資訊了哦";        self.noteLable.numberOfLines=2;        self.noteLable.textColor = [UIColor whiteColor];        self.noteLable.textAlignment = NSTextAlignmentCenter;        self.noteLable.backgroundColor = [UIColor clearColor];        [self.noteView addSubview:self.noteLable];    }    return self;}-(void)setFont:(UIFont*)font{    self.noteLable.font=font;}- (void)showNoteView:(NSString*)noteText subView:(UIView*)subView{    if (self.timer != nil && [self.timer isValid]) {        [self.timer invalidate];        self.timer = nil;    }        if (noteText != nil && [noteText length] > 0)        self.noteLable.text = noteText;        [subView addSubview:self.noteView];    [subView layoutIfNeeded];    self.timer = [NSTimer scheduledTimerWithTimeInterval:1.5 target:self selector:@selector(timerFired:) userInfo:nil repeats:NO];}- (void)timerFired:(NSTimer*)timer{    [self.timer invalidate];    //[self setFont:[BIDDeviceFont font_15]];    [self setFont:[UIFont fontWithName:@"Helvetica" size:15]];    self.timer = nil;    [self.noteView removeFromSuperview];}@end

 

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.