Ios custom message prompt box, ios custom message

Source: Internet
Author: User

Ios custom message prompt box, ios custom message

Custom prompt box, automatically disappears 3 seconds later. Such as display effect.

Code loading in the prompt box:

-(Void) viewDidLoad {[super viewDidLoad]; // change the view background color to yellow self. view. backgroundColor = [UIColor yellowColor]; // In self. load the prompt box [[BIDNoteView sharedInstance] showNoteView: @ "display prompt information" subView: self. view];}

BIDNoteView. h code:

//// BIDNoteView. h // draw a horizontal line on the 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 implementation code:

//// BIDNoteView. m // draw a horizontal line on the 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 + (BIDNoteVi Ew *) 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 = @ "no more product information"; self. noteLable. numberOfLines = 2; self. noteLable. textColor = [UIColor whiteColor]; self. noteLable. textAlignment = NSTextAlignmentCenter; self. noteLable. bac KgroundColor = [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

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.