- 浏览: 250908 次
- 性别:
- 来自: 北京
文章分类
- 全部博客 (174)
- android (5)
- android代码片段 (10)
- ios (102)
- 程序员 (5)
- 人生 (1)
- UITextField (2)
- UINavigationController (2)
- iPhone开发 (87)
- cocos2d (8)
- Object-c (1)
- Xcode4 (4)
- Mac (1)
- ASIHTTPRequest (1)
- UITableView (9)
- UIImageView (2)
- CATransition (1)
- CCMenu (1)
- UIView (2)
- UIScrollView (1)
- NSString (1)
- Git (2)
- UISwitch (1)
- UIImage (1)
- 拉伸 (1)
- delegate (1)
- NSTimer (1)
- Crash (1)
- Log (1)
- TabBar (1)
- UITabBarController (1)
- UITextView (1)
- iPad (1)
- app (1)
- test (1)
- 数据库 (1)
最新评论
-
cccoooccooco:
测了下,效率很高啊。谢谢分享。
字符串替换算法【java】 -
zkai309:
你好,
我们是ios手游《富豪传奇》的开发商,你开发的糗事囧 ...
如何判断自己是否到了该辞职的时候 -
xyxdasnjss:
吃饱了就饿 写道以后会用到
设备判断 iphone3? iphone4? iphone5? -
吃饱了就饿:
以后会用到
设备判断 iphone3? iphone4? iphone5? -
xyxdasnjss:
zhihaoshi 写道ios 5.0 中用什么方法判断 iO ...
ios 判断设备的GPS功能是否开启
#import <Foundation/Foundation.h> #import <UIKit/UIKit.h> typedef enum iToastGravity { iToastGravityTop = 1000001, iToastGravityBottom, iToastGravityCenter }iToastGravity; enum iToastDuration { iToastDurationLong = 10000, iToastDurationShort = 1000, iToastDurationNormal = 3000 }iToastDuration; typedef enum iToastType { iToastTypeInfo = -100000, iToastTypeNotice, iToastTypeWarning, iToastTypeError }iToastType; @class iToastSettings; @interface iToast : NSObject { iToastSettings *_settings; NSInteger offsetLeft; NSInteger offsetTop; NSTimer *timer; UIView *view; NSString *text; } - (void) show; - (iToast *) setDuration:(NSInteger ) duration; - (iToast *) setGravity:(iToastGravity) gravity offsetLeft:(NSInteger) left offsetTop:(NSInteger) top; - (iToast *) setGravity:(iToastGravity) gravity; - (iToast *) setPostion:(CGPoint) position; + (iToast *) makeText:(NSString *) text; -(iToastSettings *) theSettings; @end @interface iToastSettings : NSObject<NSCopying>{ NSInteger duration; iToastGravity gravity; CGPoint postition; iToastType toastType; NSDictionary *images; BOOL positionIsSet; } @property(assign) NSInteger duration; @property(assign) iToastGravity gravity; @property(assign) CGPoint postition; @property(readonly) NSDictionary *images; - (void) setImage:(UIImage *)img forType:(iToastType) type; + (iToastSettings *) getSharedSettings; @end
//.m文件
#import "iToast.h" #import <QuartzCore/QuartzCore.h> static iToastSettings *sharedSettings = nil; @interface iToast(private) - (iToast *) settings; @end @implementation iToast - (id) initWithText:(NSString *) tex{ if (self = [super init]) { text = [tex copy]; } return self; } - (void) show{ iToastSettings *theSettings = _settings; if (!theSettings) { theSettings = [iToastSettings getSharedSettings]; } UIFont *font = [UIFont systemFontOfSize:16]; CGSize textSize = [text sizeWithFont:font constrainedToSize:CGSizeMake(280, 60)]; UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(0, 0, textSize.width + 5, textSize.height + 5)]; label.backgroundColor = [UIColor clearColor]; label.textColor = [UIColor whiteColor]; label.font = font; label.text = text; label.numberOfLines = 0; label.shadowColor = [UIColor darkGrayColor]; label.shadowOffset = CGSizeMake(1, 1); UIButton *v = [UIButton buttonWithType:UIButtonTypeCustom]; v.frame = CGRectMake(0, 0, textSize.width + 10, textSize.height + 10); label.center = CGPointMake(v.frame.size.width / 2, v.frame.size.height / 2); [v addSubview:label]; v.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.7]; v.layer.cornerRadius = 5; UIWindow *window = [[[UIApplication sharedApplication] windows] objectAtIndex:0]; CGPoint point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2); if (theSettings.gravity == iToastGravityTop) { point = CGPointMake(window.frame.size.width / 2, 45); }else if (theSettings.gravity == iToastGravityBottom) { point = CGPointMake(window.frame.size.width / 2, window.frame.size.height - 45); }else if (theSettings.gravity == iToastGravityCenter) { point = CGPointMake(window.frame.size.width/2, window.frame.size.height/2); }else{ point = theSettings.postition; } point = CGPointMake(point.x + offsetLeft, point.y + offsetTop); v.center = point; NSTimer *timer1 = [NSTimer timerWithTimeInterval:((float)theSettings.duration)/1000 target:self selector:@selector(hideToast:) userInfo:nil repeats:NO]; [[NSRunLoop mainRunLoop] addTimer:timer1 forMode:NSDefaultRunLoopMode]; [window addSubview:v]; view = [v retain]; [v addTarget:self action:@selector(hideToast:) forControlEvents:UIControlEventTouchDown]; } - (void) hideToast:(NSTimer*)theTimer{ [UIView beginAnimations:nil context:NULL]; view.alpha = 0; [UIView commitAnimations]; NSTimer *timer2 = [NSTimer timerWithTimeInterval:500 target:self selector:@selector(hideToast:) userInfo:nil repeats:NO]; [[NSRunLoop mainRunLoop] addTimer:timer2 forMode:NSDefaultRunLoopMode]; } - (void) removeToast:(NSTimer*)theTimer{ [view removeFromSuperview]; } + (iToast *) makeText:(NSString *) _text{ iToast *toast = [[[iToast alloc] initWithText:_text] autorelease]; return toast; } - (iToast *) setDuration:(NSInteger ) duration{ [self theSettings].duration = duration; return self; } - (iToast *) setGravity:(iToastGravity) gravity offsetLeft:(NSInteger) left offsetTop:(NSInteger) top{ [self theSettings].gravity = gravity; offsetLeft = left; offsetTop = top; return self; } - (iToast *) setGravity:(iToastGravity) gravity{ [self theSettings].gravity = gravity; return self; } - (iToast *) setPostion:(CGPoint) _position{ [self theSettings].postition = CGPointMake(_position.x, _position.y); return self; } -(iToastSettings *) theSettings{ if (!_settings) { _settings = [[iToastSettings getSharedSettings] copy]; } return _settings; } @end @implementation iToastSettings @synthesize duration; @synthesize gravity; @synthesize postition; @synthesize images; - (void) setImage:(UIImage *) img forType:(iToastType) type{ if (!images) { images = [[NSMutableDictionary alloc] initWithCapacity:4]; } if (img) { NSString *key = [NSString stringWithFormat:@"%i", type]; [images setValue:img forKey:key]; } } + (iToastSettings *) getSharedSettings{ if (!sharedSettings) { sharedSettings = [iToastSettings new]; sharedSettings.gravity = iToastGravityCenter; sharedSettings.duration = iToastDurationShort; } return sharedSettings; } - (id) copyWithZone:(NSZone *)zone{ iToastSettings *copy = [iToastSettings new]; copy.gravity = self.gravity; copy.duration = self.duration; copy.postition = self.postition; NSArray *keys = [self.images allKeys]; for (NSString *key in keys){ [copy setImage:[images valueForKey:key] forType:[key intValue]]; } return copy; } @end
//调用
[[iToast makeText:@"需要显示的内容"] show];
发表评论
-
iOS 关闭键盘 3种方式
2015-12-11 14:21 7941,明确知道 当前的UITextField,或者UITextV ... -
在webapp中判断native app是否安装并直接打开
2015-08-31 18:15 847http://www.baidufe.com/item/cc5 ... -
iOS之ARC下的Block
2015-04-15 14:37 606http://www.cnblogs.com/tekkama ... -
UITableView 隐藏多余的Cell的分割线
2015-02-02 14:39 1563- (void)setExtraCellLineHidden ... -
UILabel顶端对齐
2014-09-10 10:15 727http://shfzhzhr.iteye.com/blog ... -
iOS7滑动返回
2014-06-24 11:48 924http://blog.csdn.net/wmqi10/ar ... -
UIView (Additon)
2014-06-19 22:23 766#import <UIKit/UIKit.h> ... -
UIColor (XYCategory)
2014-06-19 22:13 500#import <UIKit/UIKit.h> ... -
OC MD5
2014-06-19 21:50 773#import <Foundation/Foundat ... -
IOS判断设备是否已越狱(isJailbroken)
2014-06-03 21:17 700@interface UIDevice (Helper) ... -
iOS6 Xcode5 去掉Icon高亮
2014-05-25 11:13 0我昨天刚遇到这个问题,已经解决。请按照下图红色矩形所圈处的信 ... -
iOS使用NSClassFromString
2014-03-07 11:24 939http://www.cocoachina.com/b/?p ... -
iOS7 开发相关
2013-10-22 10:17 12071.UITableView reloadData 之 ... -
iPad横版开发时,宽高是反的
2013-08-14 18:01 1076最近刚开始做iPad版应用,但发现横版的时候宽高是反的,很别 ... -
UITextView 带有PlaceHolder
2013-07-31 13:23 1459#import <UIKit/UIKit.h> ... -
UITableView 只更新某行
2013-07-22 10:10 1020如果全部更新的话 用reloadData方法 如果 ... -
Xcode 4.4中LLVM compiler 4.0带来的Objective-C新语法特性
2013-07-15 10:56 907http://blog.csdn.net/totogo201 ... -
new 与 alloc/init的区别
2013-07-11 14:47 716http://blog.csdn.net/abby_shee ... -
自定义UITableViewCell上的delete按钮
2013-06-28 10:35 1068//通过UITableViewDelegate方法可以实现删 ... -
判断是否是 emoji表情
2013-06-28 09:42 2331+ (BOOL)stringContainsEmoji:(N ...
相关推荐
React Native Toast 一个用于android和ios类似于android toast提示控件,android使用原生toast, ios使用UIView Toast
IOS上类似android上得toast第三方工具,
Toast 实现了类似 Android Toast 风格的弹出提示信息框,支持图片。
c# winform 类似android toast消息功能 超级强大,多个项目在用,可插拔,封装好了,拿去就可以用了
iOS中实现android中Toast的效果,封装的代码库,使用简单
Android Toast 自定义背景、图片 随心使用
iOS编写自定义控件系列教程,仿Android的Toast控件。
类似于Android的toas,支持更新显示的内容
Android Toast 工具类
ios上实现了类似android toast的工具,可直接拿来在项目中使用
android Toast大全(五种情形)建立属于你自己的Toast
主要为大家详细介绍了android自定义Toast设定显示时间,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
Android Toast各种使用方法及DEMO
全局Toast工具类,作用:连续显示toast提示时取消上一个toast 通过ToastUtil.toast(Context(), "文本")调用
封装一个基于iOS与Android双平台的Toast组件和加载Loading组件
最近在开发中我们经常会在适配5.0以后的机型遇到各种各样的问题,其中有一个不大不小的问题就是:Toast不显示问题,这篇文章就给大家总结了Android 5.0以上Toast不显示的原因与解决方法,有需要的朋友们可以参考借鉴...
Android Toast 大全 (五种形式) 建立属于自己的 Toast
一个简单的自定义Toast资源,您可以根据自己的需要更改我的代码即可实现您想要的效果(主要是更改xml文件的布局),这是androidstudio的项目,但是不妨碍在eclipse中使用,可以直接在eclipse中新建android项目,然后将...