NSAttributedString属性介绍
/* Predefined character attributes for text. If the key is not in the dictionary, then use the default values as described below.
* 预定义的text的字符属性,如果这个key没有在设置的Dictionary中,将会使用下面介绍的。
*/
// 字体
UIKIT_EXTERN NSString *const NSFontAttributeName NS_AVAILABLE_IOS(6_0); // UIFont, default Helvetica(Neue) 12
// 段落样式
UIKIT_EXTERN NSString *const NSParagraphStyleAttributeName NS_AVAILABLE_IOS(6_0); // NSParagraphStyle, default defaultParagraphStyle
// 文字颜色
UIKIT_EXTERN NSString *const NSForegroundColorAttributeName NS_AVAILABLE_IOS(6_0); // UIColor, default blackColor
// 文字背景颜色
UIKIT_EXTERN NSString *const NSBackgroundColorAttributeName NS_AVAILABLE_IOS(6_0); // UIColor, default nil: no background
// 设置连体属性,取值为NSNumber 对象(整数),0 表示没有连体字符,1 表示使用默认的连体字符
UIKIT_EXTERN NSString *const NSLigatureAttributeName NS_AVAILABLE_IOS(6_0); // NSNumber containing integer, default 1: default ligatures, 0: no ligatures
// 设定字符间距
UIKIT_EXTERN NSString *const NSKernAttributeName NS_AVAILABLE_IOS(6_0); // NSNumber containing floating point value, in points; amount to modify default kerning. 0 means kerning is disabled.
// 设置删除线
UIKIT_EXTERN NSString *const NSStrikethroughStyleAttributeName NS_AVAILABLE_IOS(6_0); // NSNumber containing integer, default 0: no strikethrough
// 下划线
UIKIT_EXTERN NSString *const NSUnderlineStyleAttributeName NS_AVAILABLE_IOS(6_0); // NSNumber containing integer, default 0: no underline
// 填充部分颜色 same as foreground color
UIKIT_EXTERN NSString *const NSStrokeColorAttributeName NS_AVAILABLE_IOS(6_0); // UIColor, default nil: same as foreground color
// 设置笔画宽度
UIKIT_EXTERN NSString *const NSStrokeWidthAttributeName NS_AVAILABLE_IOS(6_0); // NSNumber containing floating point value, in percent of font point size, default 0: no stroke; positive for stroke alone, negative for stroke and fill (a typical value for outlined text would be 3.0)
// 阴影属性
UIKIT_EXTERN NSString *const NSShadowAttributeName NS_AVAILABLE_IOS(6_0); // NSShadow, default nil: no shadow
// 文本特殊效果
UIKIT_EXTERN NSString *const NSTextEffectAttributeName NS_AVAILABLE_IOS(7_0); // NSString, default nil: no text effect
// 文本附件,取值为NSTextAttachment对象,常用于文字图片混排
UIKIT_EXTERN NSString *const NSAttachmentAttributeName NS_AVAILABLE_IOS(7_0); // NSTextAttachment, default nil
// 设置链接属性,点击后调用浏览器打开指定URL地址
UIKIT_EXTERN NSString *const NSLinkAttributeName NS_AVAILABLE_IOS(7_0); // NSURL (preferred) or NSString
UIKIT_EXTERN NSString *const NSBaselineOffsetAttributeName NS_AVAILABLE_IOS(7_0); // NSNumber containing floating point value, in points; offset from baseline, default 0
// 设置基线偏移值,取值为 NSNumber (float),正值上偏,负值下偏
UIKIT_EXTERN NSString *const NSUnderlineColorAttributeName NS_AVAILABLE_IOS(7_0); // UIColor, default nil: same as foreground color
// 设置删除线颜色,取值为 UIColor 对象,默认值为黑色
UIKIT_EXTERN NSString *const NSStrikethroughColorAttributeName NS_AVAILABLE_IOS(7_0); // UIColor, default nil: same as foreground color
// 设置字形倾斜度,取值为 NSNumber (float),正值右倾,负值左倾
UIKIT_EXTERN NSString *const NSObliquenessAttributeName NS_AVAILABLE_IOS(7_0); // NSNumber containing floating point value; skew to be applied to glyphs, default 0: no skew
// 设置文本横向拉伸属性,取值为 NSNumber (float),正值横向拉伸文本,负值横向压缩文本
UIKIT_EXTERN NSString *const NSExpansionAttributeName NS_AVAILABLE_IOS(7_0); // NSNumber containing floating point value; log of expansion factor to be applied to glyphs, default 0: no expansion
// 设置文字书写方向,从左向右书写或者从右向左书写
UIKIT_EXTERN NSString *const NSWritingDirectionAttributeName NS_AVAILABLE_IOS(7_0); // NSArray of NSNumbers representing the nested levels of writing direction overrides as defined by Unicode LRE, RLE, LRO, and RLO characters. The control characters can be obtained by masking NSWritingDirection and NSTextWritingDirection values. LRE: NSWritingDirectionLeftToRight|NSTextWritingDirectionEmbedding, RLE: NSWritingDirectionRightToLeft|NSTextWritingDirectionEmbedding, LRO: NSWritingDirectionLeftToRight|NSTextWritingDirectionOverride, RLO: NSWritingDirectionRightToLeft|NSTextWritingDirectionOverride,
// 设置文字排版方向,取值为 NSNumber 对象(整数),0 表示横排文本,1 表示竖排文本
UIKIT_EXTERN NSString *const NSVerticalGlyphFormAttributeName NS_AVAILABLE_IOS(6_0); // An NSNumber containing an integer value. 0 means horizontal text. 1 indicates vertical text. If not specified, it could follow higher-level vertical orientation settings. Currently on iOS, it's always horizontal. The behavior for any other value is undefined.
/* This defines currently supported values for NSUnderlineStyleAttributeName and NSStrikethroughStyleAttributeName.
* 下面定义了下划线、删除线支持的样式
*/
typedef NS_ENUM(NSInteger, NSUnderlineStyle) {
NSUnderlineStyleNone = 0x00, // 不设置下划线
NSUnderlineStyleSingle = 0x01, // 设置删除线为细单实线
NSUnderlineStyleThick NS_ENUM_AVAILABLE_IOS(7_0) = 0x02, // 设置删除线为粗单实线
NSUnderlineStyleDouble NS_ENUM_AVAILABLE_IOS(7_0) = 0x09, // 设置删除线为细双实线
// http://blog.csdn.net/harvic880925/article/details/9028823 参考
NSUnderlinePatternSolid NS_ENUM_AVAILABLE_IOS(7_0) = 0x0000, // 实线
NSUnderlinePatternDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0100, // 点线
NSUnderlinePatternDash NS_ENUM_AVAILABLE_IOS(7_0) = 0x0200, // 虚线
NSUnderlinePatternDashDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0300,
NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE_IOS(7_0) = 0x0400,
NSUnderlineByWord NS_ENUM_AVAILABLE_IOS(7_0) = 0x8000
} NS_ENUM_AVAILABLE_IOS(6_0);
/* NSTextWritingDirection values used by NSWritingDirectionAttributeName. Can specify the formatting controls defined by Unicode Bidirectional Algorithm.
*/
typedef NS_ENUM(NSInteger, NSTextWritingDirection) {
NSTextWritingDirectionEmbedding = (0 << 1),
NSTextWritingDirectionOverride = (1 << 1)
} NS_ENUM_AVAILABLE_IOS(7_0);
/* This defines the currently supported value for NSTextEffectAttributeName as of iOS 7.0
*/
UIKIT_EXTERN NSString *const NSTextEffectLetterpressStyle NS_AVAILABLE_IOS(7_0);
/************************ Attribute fixing ************************/
@interface NSMutableAttributedString (NSMutableAttributedStringKitAdditions)
// This method fixes attribute inconsistencies inside range. It ensures NSFontAttributeName covers the characters, NSParagraphStyleAttributeName is only changing at paragraph boundaries, and NSTextAttachmentAttributeName is assigned to NSTextAttachmentCharacter. NSTextStorage automatically invokes this method via -ensureAttributesAreFixedInRange:.
- (void)fixAttributesInRange:(NSRange)range NS_AVAILABLE_IOS(7_0);
@end
/************************ Document formats ************************/
// Supported document types for the NSDocumentTypeDocumentAttribute key in the document attributes dictionary.
UIKIT_EXTERN NSString *const NSPlainTextDocumentType NS_AVAILABLE_IOS(7_0); // 普通文本
UIKIT_EXTERN NSString *const NSRTFTextDocumentType NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const NSRTFDTextDocumentType NS_AVAILABLE_IOS(7_0);
UIKIT_EXTERN NSString *const NSHTMLTextDocumentType NS_AVAILABLE_IOS(7_0); // HTML
// Keys for NSLayoutOrientationSectionsAttribute.
// 文字展示的方向
UIKIT_EXTERN NSString *const NSTextLayoutSectionOrientation NS_AVAILABLE_IOS(7_0); // NSNumber containing NSTextLayoutOrientation value. default: NSTextLayoutOrientationHorizontal
// 字符的范围
UIKIT_EXTERN NSString *const NSTextLayoutSectionRange NS_AVAILABLE_IOS(7_0); // NSValue containing NSRange representing a character range. default: a range covering the whole document
// Keys for options and document attributes dictionaries. They are in and out document properties used by both read/write methods.
UIKIT_EXTERN NSString *const NSDocumentTypeDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"DocumentType", one of the document types declared above. For reader methods, this key in options can specify the document type for interpreting the contents. Upon return, the document attributes can contain this key for indicating the actual format used to read the contents. For write methods, this key specifies the format for generating the data.
// NSPlainTextDocumentType document attributes
// 普通文本的编码
UIKIT_EXTERN NSString *const NSCharacterEncodingDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"CharacterEncoding", NSNumber containing integer specifying NSStringEncoding for the file; default for plain text is the default encoding. This key in options can specify the string encoding for reading the data. Upon return, the document attributes can contain the actual encoding used. For writing methods, this value is used for generating the plain text data.
UIKIT_EXTERN NSString *const NSDefaultAttributesDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"DefaultAttributes", NSDictionary containing attributes to be applied to plain files. Used by reader methods. This key in options can specify the default attributes applied to the entire document contents. The document attributes can contain this key indicating the actual attributes used.
// NSRTFTextDocumentType and NSRTFDTextDocumentType document attributes
// Document dimension
// They are document attributes used by read/write methods.
UIKIT_EXTERN NSString *const NSPaperSizeDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"PaperSize", NSValue containing CGSize (in points)
UIKIT_EXTERN NSString *const NSPaperMarginDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"PaperMargin", NSValue containing UIEdgeInsets
UIKIT_EXTERN NSString *const NSViewSizeDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"ViewSize", NSValue containing CGSize (in points)
UIKIT_EXTERN NSString *const NSViewZoomDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"ViewZoom", NSNumber containing floating point value (100 == 100% zoom)
UIKIT_EXTERN NSString *const NSViewModeDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"ViewMode", NSNumber containing integer; 0 = normal; 1 = page layout
// Document settings
// They are document attributes used by read/write methods.
UIKIT_EXTERN NSString *const NSReadOnlyDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"ReadOnly", NSNumber containing integer; if missing, or 0 or negative, not readonly; 1 or more, readonly. Note that this has nothing to do with the file system protection on the file, but instead, on how the file should be displayed to the user
UIKIT_EXTERN NSString *const NSBackgroundColorDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"BackgroundColor", UIColor, representing the document-wide page background color
UIKIT_EXTERN NSString *const NSHyphenationFactorDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"HyphenationFactor", NSNumber containing floating point value (0=off, 1=full hyphenation)
UIKIT_EXTERN NSString *const NSDefaultTabIntervalDocumentAttribute NS_AVAILABLE_IOS(7_0); // @"DefaultTabInterval", NSNumber containing floating point value, representing the document-wide default tab stop interval, in points
UIKIT_EXTERN NSString *const NSTextLayoutSectionsAttribute NS_AVAILABLE_IOS(7_0); // NSArray of dictionaries. Each dictionary describing a layout orientation section. The dictionary can have two attributes: NSTextLayoutSectionOrientation and NSTextLayoutSectionRange. When there is a gap between sections, it's assumed to have NSTextLayoutOrientationHorizontal.
@interface NSAttributedString (NSAttributedStringDocumentFormats)
// Methods initializing the receiver contents with an external document data. options specify document attributes for interpreting the document contents. NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported options key. When they are not specified, these methods will examine the data and do their best to detect the appropriate attributes. If dict is non-NULL, it will return a dictionary with various document-wide attributes accessible via NS...DocumentAttribute keys.
- (instancetype)initWithFileURL:(NSURL *)url options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
- (instancetype)initWithData:(NSData *)data options:(NSDictionary *)options documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
// Generates an NSData object for the receiver contents in range. It requires a document attributes dict specifying at least the NSDocumentTypeDocumentAttribute to determine the format to be written.
- (NSData *)dataFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
// Returns an NSFileWrapper object for the receiver contents in range. It requires a document attributes dict specifying at least the NSDocumentTypeDocumentAttribute to determine the format to be written. The method returns a directory file wrapper for those document types represented by a file package such as NSRTFDTextDocumentType; otherwise, it returns a regular-file file wrapper.
- (NSFileWrapper *)fileWrapperFromRange:(NSRange)range documentAttributes:(NSDictionary *)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
@end
@interface NSMutableAttributedString (NSMutableAttributedStringDocumentFormats)
// Methods replacing the receiver contents with an external document data. options specify document attributes for interpreting the document contents. NSDocumentTypeDocumentAttribute, NSCharacterEncodingDocumentAttribute, and NSDefaultAttributesDocumentAttribute are supported options key. When they are not specified, these methods will examine the data and do their best to detect the appropriate attributes. If dict is non-NULL, it will return a dictionary with various document-wide attributes accessible via NS...DocumentAttribute keys.
- (BOOL)readFromFileURL:(NSURL *)url options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
- (BOOL)readFromData:(NSData *)data options:(NSDictionary *)opts documentAttributes:(NSDictionary **)dict error:(NSError **)error NS_AVAILABLE_IOS(7_0);
//iOS7系统自带的返回手势
__weak typeof (self) weakSelf = self;
if ([self respondsToSelector:@selector(interactivePopGestureRecognizer)]) {
self.interactivePopGestureRecognizer.delegate = weakSelf;
}
遵守协议
https://blog.cnbluebox.com/blog/2015/02/02/autolayout2/
约束
masonry的比例问题
// width/height比为1/3.0,要求是同一个控件的属性比例
[bottomInnerView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.bottom.mas_equalTo(bottomView);
make.center.mas_equalTo(bottomView);
// 注意,这个multipliedBy的使用只能是设置同一个控件的,比如这里的bottomInnerView,
// 设置高/宽为3:1
make.height.mas_equalTo(bottomInnerView.mas_width).multipliedBy(3);
make.width.height.mas_equalTo(bottomView).priorityLow();
make.width.height.lessThanOrEqualTo(bottomView);
如何一键删除ios 模拟器里面得所有app
经过长期得使用模拟器,模拟器得app 已经达到了饱和状态,原来只会一个一个得删除app ,今天琢磨了一下,在模拟器得菜单里面有一个rest功能,然后就可以还原模拟器得设置了。
步骤:
1、打开模拟器
2、在左上角得下拉菜单选择“还原内容和设置”
3、选择“还原” ,确定 就ok了!
图解如下:
苹果推出自带的Music软件后.获取iPhone本地音乐时,使用MPMediaItem的MPMediaItemPropertyAssetURL属性为空.即使是你Make Available Offline,即把音乐下到本地.但其他属性都能正常获取.
原因:因为有点音乐是有 DRM protection的,及数字版权保护.所以你不能获取到.但是你可以获取的没有DRM protection的音乐.这就是你获取的音乐的AssetURL有的为空有的不为空了.当然不为空的url你可以按照你之前写的代码播放,而那些有DRM protection的你只能使用MPMusicPlayerController 进行播放了.当然是使用苹果的Music软件进行播放.所以别人家的应用喽,你就不能控制任何播放信息喽,比如播放,暂停,进度 and so on ... 当然即使你杀掉自己的应用,应用还是不会停的,因为是别人家的应用.
// 改变图像的尺寸,方便上传服务器
- (UIImage *) scaleFromImage: (UIImage *) image toSize: (CGSize) size
{
UIGraphicsBeginImageContext(size);
[image drawInRect:CGRectMake(0, 0, size.width, size.height)];
UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newImage;
}
[[NSNotificationCenter defaultCenter] removeObserver:observer name:nil object:self];
如果在一个类中想要执行另一个类中的方法可以使用通知
1.创建一个通知对象:使用notificationWithName:object: 或者 notificationWithName:object:userInfo:
NSNotification* notification = [NSNotification notificationWithName:kImageNotificationLoadFailed(connection.imageURL)
object:self
userInfo:[NSDictionary dictionaryWithObjectsAndKeys:error,@"error",connection.imageURL,@"imageURL",nil]];
这里需要注意的是,创建自己的通知并不是必须的。而是在创建自己的通知之前,采用NSNotificationCenter类的方法 postNotificationName:object: 和 postNotificationName:object:userInfo:更加便利的发出通知。这种情况,一般使用NSNotificationCenter的类方法defaultCenter就获得默认的通知对象,这样你就可以给该程序的默认通知中心发送通知了。注意:每一个程序都有一个自己的通知中心,即NSNotificationCenter对象。该对象采用单例设计模式,采用defaultCenter方法就可以获得唯一的NSNotificationCenter对象。
注意:NSNotification对象是不可变的,因为一旦创建,对象是不能更改的。
2.注册通知:addObserver:selector:name:object:
可以看到除了添加观察者之外,还有其接收到通知之后的执行方法入口,即selector的实参。因此为了进行防御式编程,最好先检查观察者是否定义了该方法。例如:添加观察者代码有
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(aWindowBecameMain:)
name:NSWindowDidBecomeMainNotification object:nil];
这里保证了self定义了aWindowBecameMain:方法。而对于一个任意的观察者observer,不能保证其对应的selector有aWindowBecameMain:,可采用[observer respondsToSelector:@selector(aWindowBecameMain:)]] 进行检查。所以完整的添加观察者过程为:
if([observer respondsToSelector:@selector(aWindowBecameMain:)]) {
[[NSNotificationCenter defaultCenter] addObserver:observer selector:@selector(aWindowBecameMain:) name:NSWindowDidBecomeMainNotification object:nil];
}
注意到addObserver:selector:name:object:不仅指定一个观察者,指定通知中心发送给观察者的消息,还有接收通知的名字,以及指定的对象。一般来说不需要指定name和object,但如果仅仅指定了一个object,观察者将收到该对象的所有通知。例如将上面的代码中name改为nil,那么观察者将接收到object对象的所有消息,但是确定不了接收这些消息的顺序。如果指指定一个通知名称,观察者将收到它每次发出的通知。例如,上面的代码中object为nil,那么客户对象(self)将收到任何对象发出NSWindowDidBecomeMainNotification通知。如果既没有指定指定object,也没有指定name,那么该观察者将收到所有对象的所有消息。
3.发送通知:postNotificationName:object:或者performSelectorOnMainThread:withObject:waitUntilDone:
例如程序可以实现将一个文本可以进行一系列的转换,例如对于一个实例、RTF格式转换成ASCII格式。而转换在一个类(如Converter类)的对象中得到处理,在诚寻执行过程中可以加入或者删除这种转换。而且当添加或者删除Converter操作时,你的程序可能需要通知其他的对象,但是这些Converter对象并不需要知道被通知对象是什么,能干什么。你只需要声明两个通知,"ConverterAdded" 和 "ConverterRemoved",并且在某一事件发生时就发出这两个通知。
当一个用户安装或者删除一个Converter,它将发送下面的消息给通知中心:
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ConverterAdded" object:self];
或者是
[[NSNotificationCenter defaultCenter]
postNotificationName:@"ConverterRemoved" object:self];
通知中心将会区分它们对象对这些通知感兴趣并且通知他们。如果除了关心观察者的通知名称和观察的对象,还关心其他之外的对象,那么就把之外的对象放在通知的可选字典中,或者用方法postNotificationName:object:userInfo:。
而采用performSelectorOnMainThread:withObject:waitUntilDone:则是直接调用NSNotification的方法postNotification,而postNotificationName和object参数可以放到withObject的实参中。例如:
[[NSNotificationCenter defaultCenter] performSelectorOnMainThread:@selector(postNotification:) withObject:notification waitUntilDone:YES];//注意这里的notification为自定义的一个通知对象,可定义为NSNotification* notification = [NSNotification notificationWithName:@"ConverterAdded"object:self];//那么它的作用与上面的一致
4.移除通知:removeObserver:和removeObserver:name:object:
其中,removeObserver:是删除通知中心保存的调度表一个观察者的所有入口,而removeObserver:name:object:是删除匹配了通知中心保存的调度表中观察者的一个入口。
这个比较简单,直接调用该方法就行。例如:
[[NSNotificationCenter defaultCenter] removeObserver:observer name:nil object:self];
注意参数notificationObserver为要删除的观察者,一定不能置为nil。
PS:这里简单说一下通知中心保存的调度表。通知中心的调度表是给一些观察者指定的一些通知集。一个通知集是通知中心发出的通知的子集。每个表的入口包含:
通知观察者(必须要的)、通知名称、通知的发送者。
下图表示通知集中指定的通知的调用表入口的四种类型:
下图表示四种观察者的调度表
最后,提醒一下观察者收到通知的顺序是没有定义的。同时通知发出和观察的对象有可能是一样的。通知中心同步转发通知给观察者,就是说 postNotification: 方法直到接收并处理完通知才返回值。要想异步的发送通知,可以使用NSNotificationQueue。在多线程编程中,通知一般是在一个发出通知的那个线程中转发,但也可能是不在同一个线程中转发通知。
在一个页面有两个tableView,当点击左边的TableView的cell时右边的tableView会显示对应的数据
在didSelectRowAtIndexPath 里
//左边tableView
if (tableView == _firstTableView) {
_isRelate = NO;
[self.firstTableView selectRowAtIndexPath:indexPath animated:NO scrollPosition:UITableViewScrollPositionMiddle];
//点击了左边的cell,让右边的tableView跟着滚动
[self.secondTableView scrollToRowAtIndexPath:[NSIndexPath indexPathForItem:0 inSection:indexPath.row] atScrollPosition:UITableViewScrollPositionTop animated:YES];
在实现。- (void)tableView:(UITableView *)tableView willDisplayHeaderView:(UIView *)view forSection:(NSInteger)section {
if (_isRelate) {
NSInteger topCellSection = [[[tableView indexPathsForVisibleRows] firstObject] section];
if (tableView == _secondTableView) {
[self.firstTableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:topCellSection inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
}
}
- (void)tableView:(UITableView *)tableView didEndDisplayingFooterView:(UIView *)view forSection:(NSInteger)section {
if (_isRelate) {
NSInteger topCellSection = [[[tableView indexPathsForVisibleRows] firstObject] section];
if (tableView == _secondTableView) {
[self.firstTableView selectRowAtIndexPath:[NSIndexPath indexPathForItem:topCellSection inSection:0] animated:YES scrollPosition:UITableViewScrollPositionMiddle];
}
}
}
内存测试
蒲公英 Testin云测
注册通知 适配 ui
我们可以通过 command+option+shift+esc 组合键(需多按几秒,直至程序退出)
// 004xmpp聊天
//
// Created by mac on 16/3/26.
// Copyright © 2016年 mac. All rights reserved.
//
#import <Foundation/Foundation.h>
@interface LFLaccount : NSObject
//登录
@property(nonatomic,copy)NSString *loginuser;
@property(nonatomic,copy)NSString *password;
//注册
@property(nonatomic,copy)NSString *registeruser;
@property(nonatomic,copy)NSString *registerpsw;
@property(nonatomic,readonly,copy)NSString *domain;
@property(nonatomic,readonly,copy)NSString *host;
//判断用户是否登录
@property(nonatomic,assign,getter=isLogin)BOOL login;
+(instancetype)shareaccount;
//保存用户数据到沙河
-(void)sendTobox;
@end
1.url编码
ios中http请求遇到汉字的时候,需要转化成UTF-8,用到的方法是:
NSString * encodingString = [urlString stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
2.url解码
请求后,返回的数据,如何显示的是这样的格式:%3A%2F%2F,此时需要我们进行UTF-8解码,用到的方法是:
NSString *str = [model.album_name stringByReplacingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
fir.im
API 简介
fir.im API 接口全新升级,可以应用在你需要集成的环境当中,灵活地使用 API 可实现检测更新,持续集成更新应用等功能。
注意事项:
参数说明
//
// LFLaccount.m
// 004xmpp聊天
//
// Created by mac on 16/3/26.
// Copyright © 2016年 mac. All rights reserved.
//
#import "LFLaccount.h"
#define userKey @"user"
#define pswKey @"psw"
#define loginKey @"login"
@implementation LFLaccount
-(NSString *)domain{
return domain;
}
-(NSString *)host{
return host;
}
+(instancetype)shareaccount{
return [[self alloc]init];
}
//分配内存创建对象都会调用此方法
+(instancetype)allocWithZone:(struct _NSZone *)zone{
NSLog(@"账户信息");
static LFLaccount *account ;
static dispatch_once_t once;
//为了线程安全
//如果有三个线程同时调用此方法,一次只能有一个线程调用
dispatch_once(&once, ^{
account = [super allocWithZone:zone];
//从沙河获取上次登录信息
NSUserDefaults *defuat = [NSUserDefaults standardUserDefaults];
account.loginuser = [defuat objectForKey:userKey];
account.password = [defuat objectForKey:pswKey];
account.login = [defuat boolForKey:loginKey];
});
return account;
}
-(void)sendTobox{
NSUserDefaults *defuat = [NSUserDefaults standardUserDefaults];
[defuat setObject:self.loginuser forKey:userKey];
[defuat setObject:self.password forKey:pswKey];
[defuat setBool:self.login forKey:loginKey];
//同步保存
[defuat synchronize];
}
@end
获取app系统的音量大小
MPVolumeView *volumeView = [[MPVolumeView alloc] init];
volumeViewSlider= nil;
for (UIView *view in [volumeView subviews]){
if ([view.class.description isEqualToString:@"MPVolumeSlider"]){
volumeViewSlider = (UISlider *)view;
break;
}
}
slider.value = volumeViewSlider.value ;
backgroundView.layer.shadowColor = [UIColor colorWithHexString:@"#888a91"].CGColor;
backgroundView.layer.shadowOpacity = 0.9;
backgroundView.layer.shadowOffset = CGSizeMake(-0, -1.7);