CollectionView的item怎么glide实现圆角这样局部圆角的效果

iOS开发,UICollectionView的使用_密斯L_新浪博客
iOS开发,UICollectionView的使用
在做这个分享小界面的时候,开始是想把图标设置成按钮,但是要考虑的问题很多,比如按钮标题宽度大于图片宽度啊,或者frame值啦等等,后来决定用UICollectionView来布局(这看上去本来就是一个collectionView),但是却发现这个不怎么用到的控件,用起来并不是那么简单。
图1-需要的界面&
第一步:子类化单元格CollectionViewCell和头视图CollectionHeaderView
(根据需求自己定义所需控件)
第二步:创建_collectionView
& if (_collectionView ==
//首先创建布局对象,直接用init方法创建collectionView没用
UICollectionViewFlowLayout
*layout=[[UICollectionViewFlowLayoutalloc]
//创建_collectionView
_collectionView =
[[UICollectionViewalloc]
initWithFrame:CGRectMake(0,
屏高-视图高, 屏宽,
collectionViewLayout:layout];
//设置圆角(没有需求可省略)
_collectionView.layer.cornerRadius
_collectionView.layer.masksToBounds
//背景颜色(没有需求可省略)
_collectionView.backgroundColor =
kDefault_bgColor;
//每一个单元格的大小
layout.itemSize =
CGSizeMake(kScreen_width /
4.0, 25 + 44 +
//每行元素的间距和每个元素的间距,不设置的话会自动整齐排列成图2的丑样子
layout.minimumLineSpacing = 0;
layout.minimumInteritemSpacing = 0;
图2-没有设置间距的效果
//注册单元格
[_collectionView&registerClass
:[CollectionViewCell&class
] forCellWithReuseIdentifier :
@"shareCell"];
//注册头视图(如果需要尾视图再注册一遍尾视图,kind选择UICollectionElementKindSectionFooter,ReuseIdentifier另设置)
[_collectionView&registerClass:[CollectionHeaderView&class]
forSupplementaryViewOfKind:UICollectionElementKindSectionHeader&withReuseIdentifier:@"collectionHeaderView"];
//设置数据源和代理(给所属控制器签署协议UICollectionViewDelegate和UICollectionViewDataSource)
_collectionView.delegate =
_collectionView.dataSource =
& //添加到父视图
[selfaddSubview:_collectionView];
第三步:设置​单元格
(NSInteger)numberOfSectionsInCollectionView:(UICollectionView
*)collectionView {
//一组视图
(NSInteger)collectionView:(UICollectionView
*)collectionView
numberOfItemsInSection:(NSInteger)section {
return&单元格的个数;
- (UICollectionViewCell
*)collectionView:(UICollectionView *)collectionView
cellForItemAtIndexPath:(NSIndexPath *)indexPath {
& & CollectionViewCell*cell =
[collectionView dequeueReusableCellWithReuseIdentifier
: @"shareCell"forIndexPath
:indexPath];
//cell的相关设置省略
& & return
第四步:设置头视图​
(UICollectionReusableView
*)collectionView:(UICollectionView *)collectionView
viewForSupplementaryElementOfKind:(NSString *)kind
atIndexPath:(NSIndexPath *)indexPath {
UICollectionReusableView *resuableView =
if (kind ==
UICollectionElementKindSectionHeader) {
& CollectionHeaderView
*collectionHeaderView = [collectionView
dequeueReusableSupplementaryViewOfKind:UICollectionElementKindSectionHeaderwithReuseIdentifier:@"collectionHeaderView"forIndexPath:indexPath];
& collectionHeaderView.delegate =
& resuableView = collectionHeaderV
& & return
//设置头视图的宽和头视图的高
(CGSize)collectionView:(UICollectionView
*)collectionView layout:(UICollectionViewLayout
*)collectionViewLayout
referenceSizeForHeaderInSection:(NSInteger)section
returnCGSizeMake(头视图的宽,
头视图的高);
​这样就设置好了!头视图一定要自定义,否则没有办法显示。。。(难道是我打开的方式不对?)
博客等级:
博客积分:0
博客访问:5,461
关注人气:0
荣誉徽章:介绍了如何使用swift纯代码构建UIColletionView,本篇继续介绍如何对其分组、设置分组标题、cell 圆角、选中变色。效果图如下:
1.设置Header布局SHomeHeader,继承自UICollectionReusableView。
SHomeHeader.swift
Created by wangjie on 16/5/4.
Copyright & 2016年 wangjie. All rights reserved.
import UIKit
class SHomeHeader: UICollectionReusableView {
var titleLabel:UILabel?//title
override init(frame: CGRect) {
super.init(frame: frame)
initView()
func initView(){
titleLabel = UILabel(frame: CGRectMake(0, 0, SCREEN_WIDTH, 30))
titleLabel?.backgroundColor = HEADER_BG_COLOR
self .addSubview(titleLabel!)
required init?(coder aDecoder: NSCoder) {
fatalError(&init(coder:) has not been implemented&)
2.为UICollectionReusableView注册header。
//注册header
collectionView!.registerClass(SHomeHeader.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerIdentifier)
3.自定义Header并设置宽高。
//设置HeadView的宽高
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -& CGSize{
return CGSize(width: SCREEN_WIDTH, height: headerHeight)
//返回自定义HeadView
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -& UICollectionReusableView{
var v = SHomeHeader()
if kind == UICollectionElementKindSectionHeader{
v = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: headerIdentifier, forIndexPath: indexPath) as! SHomeHeader
let title:String = headerArr[indexPath.section] as! String
v.titleLabel?.text = title
4.设置选中颜色及圆角Cell。
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.cornerRadius = 4
cell?.backgroundColor = UIColor.yellowColor()
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.cornerRadius = 4
cell?.backgroundColor = UIColor.whiteColor()
5.自定义圆角带边框的UICollectionViewCell。
SHomeCell.swift
Created by wangjie on 16/5/4.
Copyright & 2016年 wangjie. All rights reserved.
import UIKit
class SHomeCell: UICollectionViewCell {
var titleLabel:UILabel?//title
override init(frame: CGRect) {
super.init(frame: frame)
initView()
required init?(coder aDecoder: NSCoder) {
fatalError(&init(coder:) has not been implemented&)
func initView(){
titleLabel = UILabel(frame: CGRectMake(0, 0, (SCREEN_WIDTH - 20)/3, (SCREEN_WIDTH - 20)/3))
titleLabel?.layer.cornerRadius = 4
titleLabel?.layer.borderWidth = 0.5
titleLabel?.textAlignment = NSTextAlignment.Center
titleLabel?.layoutMargins = UIEdgeInsets(top:0, left:0, bottom:0, right:0)
self .addSubview(titleLabel!)
6. UIViewController 完整代码。
SHomeViewController.swift
Created by wangjie on 16/5/4.
Copyright & 2016年 wangjie. All rights reserved.
import UIKit
class SHomeViewController:UIViewController,UICollectionViewDelegate,UICollectionViewDataSource,UICollectionViewDelegateFlowLayout{
var collectionView : UICollectionView?
var dataArr = NSMutableArray()//数据源
var headerArr = NSMutableArray()//分组标题
let headerHeight:CGFloat = 30
let cellHeight:CGFloat = (SCREEN_WIDTH - 20)/3
let headerIdentifier:String = &headView&
override func viewDidLoad() {
super.viewDidLoad()
initView()
initData()
func initView(){
let layout = UICollectionViewFlowLayout()
self.view.backgroundColor = UIColor.whiteColor()
layout.sectionInset = UIEdgeInsetsMake(5, 5, 5, 5);
layout.minimumInteritemSpacing = 5; // this number could be anything &=5. Need it here because the default is 10.
layout.minimumLineSpacing = 4.0 //设置行间距
layout.itemSize = CGSizeMake((SCREEN_WIDTH - 20)/3, (SCREEN_WIDTH - 20)/3) // 20 is 2*5 for the 2 edges plus 2*5 for the spaces between the cells
collectionView = UICollectionView(frame: CGRectMake(0, 20, SCREEN_WIDTH, SCREEN_HEIGHT), collectionViewLayout: layout)
//注册一个cell
collectionView!.registerClass(SHomeCell.self, forCellWithReuseIdentifier:&cell&)
collectionView?.delegate =
collectionView?.dataSource =
collectionView?.backgroundColor = UIColor.whiteColor()
//设置每一个cell的宽高
self.view.addSubview(collectionView!)
//注册header
collectionView!.registerClass(SHomeHeader.classForCoder(), forSupplementaryViewOfKind: UICollectionElementKindSectionHeader, withReuseIdentifier: headerIdentifier)
func initData(){
initHeaderData()
initSelectionData()
self.collectionView?.reloadData()
override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()
//返回多少个组
func numberOfSectionsInCollectionView(collectionView: UICollectionView) -& Int {
return headerArr.count
//返回多少个cell
func collectionView(collectionView: UICollectionView, numberOfItemsInSection section: Int) -& Int {
return dataArr.count
//返回自定义的cell
func collectionView(collectionView: UICollectionView, cellForItemAtIndexPath indexPath: NSIndexPath) -& UICollectionViewCell {
let cell = collectionView.dequeueReusableCellWithReuseIdentifier(&cell&, forIndexPath: indexPath) as! SHomeCell
let title = dataArr[indexPath.row]
cell.titleLabel?.text = title as? String
return cell
func initHeaderData() {
headerArr.addObject(&header 1&)
headerArr.addObject(&header 2&)
headerArr.addObject(&header 3&)
func initSelectionData() {
dataArr.addObject(&selection 1&)
dataArr.addObject(&selection 2&)
dataArr.addObject(&selection 3&)
//设置HeadView的宽高
func collectionView(collectionView: UICollectionView, layout collectionViewLayout: UICollectionViewLayout, referenceSizeForHeaderInSection section: Int) -& CGSize{
return CGSize(width: SCREEN_WIDTH, height: headerHeight)
//返回自定义HeadView
func collectionView(collectionView: UICollectionView, viewForSupplementaryElementOfKind kind: String, atIndexPath indexPath: NSIndexPath) -& UICollectionReusableView{
var v = SHomeHeader()
if kind == UICollectionElementKindSectionHeader{
v = collectionView.dequeueReusableSupplementaryViewOfKind(kind, withReuseIdentifier: headerIdentifier, forIndexPath: indexPath) as! SHomeHeader
let title:String = headerArr[indexPath.section] as! String
v.titleLabel?.text = title
func collectionView(collectionView: UICollectionView, didSelectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.cornerRadius = 4
cell?.backgroundColor = UIColor.yellowColor()
func collectionView(collectionView: UICollectionView, didDeselectItemAtIndexPath indexPath: NSIndexPath) {
let cell = collectionView.cellForItemAtIndexPath(indexPath)
cell!.layer.cornerRadius = 4
cell?.backgroundColor = UIColor.whiteColor()
7. 完整代码见:iOS(123)
在这里总结一些iOS开发中的小技巧,能大大方便我们的开发,持续更新。
UITableView的Group样式下顶部空白处理
//分组列表头部空白处理
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 0, 0.1)];
self.tableView.tableHeaderView =
UITableView的plain样式下,取消区头停滞效果
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
CGFloat sectionHeaderHeight = sectionHead.
if (scrollView.contentOffset.y&=sectionHeaderHeight&&scrollV.contentOffset.y&=0)
scrollView.contentInset = UIEdgeInsetsMake(-scrollView.contentOffset.y, 0, 0, 0);
else if(scrollView.contentOffset.y&=sectionHeaderHeight)
scrollView.contentInset = UIEdgeInsetsMake(-sectionHeaderHeight, 0, 0, 0);
那个,其实,还是用Group样式吧哈哈。
获取某个view所在的控制器
- (UIViewController *)viewController
UIViewController *viewController =
UIResponder *next = self.nextR
while (next)
if ([next isKindOfClass:[UIViewController class]])
viewController = (UIViewController *)
next = next.nextR
return viewC
两种方法删除NSUserDefaults所有记录
NSString *appDomain = [[NSBundle mainBundle] bundleIdentifier];
[[NSUserDefaults standardUserDefaults] removePersistentDomainForName:appDomain];
- (void)resetDefaults
NSUserDefaults * defs = [NSUserDefaults standardUserDefaults];
NSDictionary * dict = [defs dictionaryRepresentation];
for (id key in dict)
[defs removeObjectForKey:key];
[defs synchronize];
打印系统所有已注册的字体名称
#pragma mark - 打印系统所有已注册的字体名称
void enumerateFonts()
for(NSString *familyName in [UIFont familyNames])
NSLog(@&%@&,familyName);
NSArray *fontNames = [UIFont fontNamesForFamilyName:familyName];
for(NSString *fontName in fontNames)
NSLog(@&\t|- %@&,fontName);
取图片某一像素点的颜色 在UIImage的分类中
- (UIColor *)colorAtPixel:(CGPoint)point
if (!CGRectContainsPoint(CGRectMake(0.0f, 0.0f, self.size.width, self.size.height), point))
CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
int bytesPerPixel = 4;
int bytesPerRow = bytesPerPixel * 1;
NSUInteger bitsPerComponent = 8;
unsigned char pixelData[4] = {0, 0, 0, 0};
CGContextRef context = CGBitmapContextCreate(pixelData,
bitsPerComponent,
bytesPerRow,
colorSpace,
kCGImageAlphaPremultipliedLast | kCGBitmapByteOrder32Big);
CGColorSpaceRelease(colorSpace);
CGContextSetBlendMode(context, kCGBlendModeCopy);
CGContextTranslateCTM(context, -point.x, point.y - self.size.height);
CGContextDrawImage(context, CGRectMake(0.0f, 0.0f, self.size.width, self.size.height), self.CGImage);
CGContextRelease(context);
CGFloat red
= (CGFloat)pixelData[0] / 255.0f;
CGFloat green = (CGFloat)pixelData[1] / 255.0f;
CGFloat blue
= (CGFloat)pixelData[2] / 255.0f;
CGFloat alpha = (CGFloat)pixelData[3] / 255.0f;
return [UIColor colorWithRed:red green:green blue:blue alpha:alpha];
字符串反转
- (NSString *)reverseWordsInString:(NSString *)str
NSMutableString *newString = [[NSMutableString alloc] initWithCapacity:str.length];
for (NSInteger i = str.length - 1; i &= 0 ; i --)
unichar ch = [str characterAtIndex:i];
[newString appendFormat:@&%c&, ch];
return newS
//第二种:
- (NSString*)reverseWordsInString:(NSString*)str
NSMutableString *reverString = [NSMutableString stringWithCapacity:str.length];
[str enumerateSubstringsInRange:NSMakeRange(0, str.length) options:NSStringEnumerationReverse | NSStringEnumerationByComposedCharacterSequences
usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
[reverString appendString:substring];
return reverS
禁止锁屏,
默认情况下,当设备一段时间没有触控动作时,iOS会锁住屏幕。但有一些应用是不需要锁屏的,比如视频播放器。
[UIApplication sharedApplication].idleTimerDisabled = YES;
[[UIApplication sharedApplication] setIdleTimerDisabled:YES];
模态推出透明界面
UIViewController *vc = [[UIViewController alloc] init];
UINavigationController *na = [[UINavigationController alloc] initWithRootViewController:vc];
if ([[[UIDevice currentDevice] systemVersion] floatValue] &= 8.0)
na.modalPresentationStyle = UIModalPresentationOverCurrentC
self.modalPresentationStyle=UIModalPresentationCurrentC
[self presentViewController:na animated:YES completion:nil];
Xcode调试不显示内存占用
editSCheme
里面有个选项叫叫做enable zoombie Objects
显示隐藏文件
defaults write com.apple.finder AppleShowAllFiles -bool true
killall Finder
defaults write com.apple.finder AppleShowAllFiles -bool false
killall Finder
字符串按多个符号分割
iOS跳转到App Store下载应用评分
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@&itms-apps:///WebObjects/MZStore.woa/wa/viewContentsUserReviews?type=Purple+Software&id=APPID&]];
iOS 获取汉字的拼音
+ (NSString *)transform:(NSString *)chinese
//将NSString装换成NSMutableString
NSMutableString *pinyin = [chinese mutableCopy];
//将汉字转换为拼音(带音标)
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformMandarinLatin, NO);
NSLog(@&%@&, pinyin);
//去掉拼音的音标
CFStringTransform((__bridge CFMutableStringRef)pinyin, NULL, kCFStringTransformStripCombiningMarks, NO);
NSLog(@&%@&, pinyin);
//返回最近结果
手动更改iOS状态栏的颜色
- (void)setStatusBarBackgroundColor:(UIColor *)color
UIView *statusBar = [[[UIApplication sharedApplication] valueForKey:@&statusBarWindow&] valueForKey:@&statusBar&];
if ([statusBar respondsToSelector:@selector(setBackgroundColor:)])
statusBar.backgroundColor =
判断当前ViewController是push还是present的方式显示的
NSArray *viewcontrollers=self.navigationController.viewC
if (viewcontrollers.count & 1)
if ([viewcontrollers objectAtIndex:viewcontrollers.count - 1] == self)
//push方式
[self.navigationController popViewControllerAnimated:YES];
//present方式
[self dismissViewControllerAnimated:YES completion:nil];
获取实际使用的LaunchImage图片
- (NSString *)getLaunchImageName
CGSize viewSize = self.window.bounds.
NSString *viewOrientation = @&Portrait&;
NSString *launchImageName =
NSArray* imagesDict = [[[NSBundle mainBundle] infoDictionary] valueForKey:@&UILaunchImages&];
for (NSDictionary* dict in imagesDict)
CGSize imageSize = CGSizeFromString(dict[@&UILaunchImageSize&]);
if (CGSizeEqualToSize(imageSize, viewSize) && [viewOrientation isEqualToString:dict[@&UILaunchImageOrientation&]])
launchImageName = dict[@&UILaunchImageName&];
return launchImageN
iOS在当前屏幕获取第一响应
UIWindow * keyWindow = [[UIApplication sharedApplication] keyWindow];
UIView * firstResponder = [keyWindow performSelector:@selector(firstResponder)];
判断对象是否遵循了某协议
if ([self.selectedController conformsToProtocol:@protocol(RefreshPtotocol)])
[self.selectedController performSelector:@selector(onTriggerRefresh)];
判断view是不是指定视图的子视图
BOOL isView = [textView isDescendantOfView:self.view];
NSArray 快速求总和 最大值 最小值 和 平均值
NSArray *array = [NSArray arrayWithObjects:@&2.0&, @&2.3&, @&3.0&, @&4.0&, @&10&, nil];
CGFloat sum = [[array valueForKeyPath:@&@sum.floatValue&] floatValue];
CGFloat avg = [[array valueForKeyPath:@&@avg.floatValue&] floatValue];
CGFloat max =[[array valueForKeyPath:@&@max.floatValue&] floatValue];
CGFloat min =[[array valueForKeyPath:@&@min.floatValue&] floatValue];
NSLog(@&%f\n%f\n%f\n%f&,sum,avg,max,min);
修改UITextField中Placeholder的文字颜色
[textField setValue:[UIColor redColor] forKeyPath:@&_placeholderLabel.textColor&];
关于NSDateFormatter的格式
G: 公元时代,例如AD公元
yy: 年的后2位
yyyy: 完整年
MM: 月,显示为1-12
MMM: 月,显示为英文月份简写,如 Jan
MMMM: 月,显示为英文月份全称,如 Janualy
dd: 日,2位数表示,如02
d: 日,1-2位显示,如 2
EEE: 简写星期几,如Sun
EEEE: 全写星期几,如Sunday
aa: 上下午,AM/PM
H: 时,24小时制,0-23
K:时,12小时制,0-11
m: 分,1-2位
mm: 分,2位
s: 秒,1-2位
ss: 秒,2位
获取一个类的所有子类
+ (NSArray *) allSubclasses
Class myClass = [self class];
NSMutableArray *mySubclasses = [NSMutableArray array];
unsigned int numOfC
Class *classes = objc_copyClassList(&numOfC);
for (unsigned int ci = 0; ci & numOfC ci++)
Class superClass = classes[ci];
superClass = class_getSuperclass(superClass);
} while (superClass && superClass != myClass);
if (superClass)
[mySubclasses addObject: classes[ci]];
free(classes);
return myS
监测IOS设备是否设置了代理,需要CFNetwork.framework
NSDictionary *proxySettings = (__bridge NSDictionary *)(CFNetworkCopySystemProxySettings());
NSArray *proxies = (__bridge NSArray *)(CFNetworkCopyProxiesForURL((__bridge CFURLRef _Nonnull)([NSURL URLWithString:@&&]), (__bridge CFDictionaryRef _Nonnull)(proxySettings)));
NSLog(@&\n%@&,proxies);
NSDictionary *settings = proxies[0];
NSLog(@&%@&,[settings objectForKey:(NSString *)kCFProxyHostNameKey]);
NSLog(@&%@&,[settings objectForKey:(NSString *)kCFProxyPortNumberKey]);
NSLog(@&%@&,[settings objectForKey:(NSString *)kCFProxyTypeKey]);
if ([[settings objectForKey:(NSString *)kCFProxyTypeKey] isEqualToString:@&kCFProxyTypeNone&])
NSLog(@&没代理&);
NSLog(@&设置了代理&);
阿拉伯数字转中文格式
+(NSString *)translation:(NSString *)arebic
NSString *str =
NSArray *arabic_numerals = @[@&1&,@&2&,@&3&,@&4&,@&5&,@&6&,@&7&,@&8&,@&9&,@&0&];
NSArray *chinese_numerals = @[@&一&,@&二&,@&三&,@&四&,@&五&,@&六&,@&七&,@&八&,@&九&,@&零&];
NSArray *digits = @[@&个&,@&十&,@&百&,@&千&,@&万&,@&十&,@&百&,@&千&,@&亿&,@&十&,@&百&,@&千&,@&兆&];
NSDictionary *dictionary = [NSDictionary dictionaryWithObjects:chinese_numerals forKeys:arabic_numerals];
NSMutableArray *sums = [NSMutableArray array];
for (int i = 0; i & str. i ++) {
NSString *substr = [str substringWithRange:NSMakeRange(i, 1)];
NSString *a = [dictionary objectForKey:substr];
NSString *b = digits[str.length -i-1];
NSString *sum = [a stringByAppendingString:b];
if ([a isEqualToString:chinese_numerals[9]])
if([b isEqualToString:digits[4]] || [b isEqualToString:digits[8]])
if ([[sums lastObject] isEqualToString:chinese_numerals[9]])
[sums removeLastObject];
sum = chinese_numerals[9];
if ([[sums lastObject] isEqualToString:sum])
[sums addObject:sum];
NSString *sumStr = [sums componentsJoinedByString:@&&];
NSString *chinese = [sumStr substringToIndex:sumStr.length-1];
NSLog(@&%@&,str);
NSLog(@&%@&,chinese);
Base64编码与NSString对象或NSData对象的转换
// Create NSData object
NSData *nsdata = [@&iOS Developer Tips encoded in Base64&
dataUsingEncoding:NSUTF8StringEncoding];
// Get NSString from NSData object in Base64
NSString *base64Encoded = [nsdata base64EncodedStringWithOptions:0];
// Print the Base64 encoded string
NSLog(@&Encoded: %@&, base64Encoded);
// Let's go the other way...
// NSData from the Base64 encoded str
NSData *nsdataFromBase64String = [[NSData alloc]
initWithBase64EncodedString:base64Encoded options:0];
// Decoded NSString from the NSData
NSString *base64Decoded = [[NSString alloc]
initWithData:nsdataFromBase64String encoding:NSUTF8StringEncoding];
NSLog(@&Decoded: %@&, base64Decoded);
取消UICollectionView的隐式动画
UICollectionView在reloadItems的时候,默认会附加一个隐式的fade动画,有时候很讨厌,尤其是当你的cell是复合cell的情况下(比如cell使用到了UIStackView)。
下面几种方法都可以帮你去除这些动画
[UIView performWithoutAnimation:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
[UIView animateWithDuration:0 animations:^{
[collectionView performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:nil];
[UIView setAnimationsEnabled:NO];
[self.trackPanel performBatchUpdates:^{
[collectionView reloadItemsAtIndexPaths:@[[NSIndexPath indexPathForItem:index inSection:0]]];
} completion:^(BOOL finished) {
[UIView setAnimationsEnabled:YES];
让Xcode的控制台支持LLDB类型的打印
打开终端输入三条命令:
touch ~/.lldbinit
echo display @import UIKit && ~/.lldbinit
echo target stop-hook add -o \&target stop-hook disable\& && ~/.lldbinit
CocoaPods pod install/pod update更新慢的问题
pod install --verbose --no-repo-update
pod update --verbose --no-repo-update
如果不加后面的参数,默认会升级CocoaPods的spec仓库,加一个参数可以省略这一步,然后速度就会提升不少
UIImage 占用内存大小
UIImage *image = [UIImage imageNamed:@&aa&];
NSUInteger size
= CGImageGetHeight(image.CGImage) * CGImageGetBytesPerRow(image.CGImage);
GCD timer定时器
dispatch_queue_t queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0);
dispatch_source_t timer = dispatch_source_create(DISPATCH_SOURCE_TYPE_TIMER, 0, 0,queue);
dispatch_source_set_timer(timer,dispatch_walltime(NULL, 0),1.0*NSEC_PER_SEC, 0); //每秒执行
dispatch_source_set_event_handler(timer, ^{
//@&倒计时结束,关闭&
dispatch_source_cancel(timer);
dispatch_async(dispatch_get_main_queue(), ^{
dispatch_resume(timer);
图片上绘制文字 写一个UIImage的category
- (UIImage *)imageWithTitle:(NSString *)title fontSize:(CGFloat)fontSize
//画布大小
CGSize size=CGSizeMake(self.size.width,self.size.height);
//创建一个基于位图的上下文
UIGraphicsBeginImageContextWithOptions(size,NO,0.0);//opaque:NO
[self drawAtPoint:CGPointMake(0.0,0.0)];
//文字居中显示在画布上
NSMutableParagraphStyle* paragraphStyle = [[NSParagraphStyle defaultParagraphStyle] mutableCopy];
paragraphStyle.lineBreakMode = NSLineBreakByCharW
paragraphStyle.alignment=NSTextAlignmentC//文字居中
//计算文字所占的size,文字居中显示在画布上
CGSize sizeText=[title boundingRectWithSize:self.size options:NSStringDrawingUsesLineFragmentOrigin
attributes:@{NSFontAttributeName:[UIFont systemFontOfSize:fontSize]}context:nil].
CGFloat width = self.size.
CGFloat height = self.size.
CGRect rect = CGRectMake((width-sizeText.width)/2, (height-sizeText.height)/2, sizeText.width, sizeText.height);
//绘制文字
[title drawInRect:rect withAttributes:@{ NSFontAttributeName:[UIFont systemFontOfSize:fontSize],NSForegroundColorAttributeName:[ UIColor whiteColor],NSParagraphStyleAttributeName:paragraphStyle}];
//返回绘制的新图形
UIImage *newImage= UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return newI
查找一个视图的所有子视图
- (NSMutableArray *)allSubViewsForView:(UIView *)view
NSMutableArray *array = [NSMutableArray arrayWithCapacity:0];
for (UIView *subView in view.subviews)
[array addObject:subView];
if (subView.subviews.count & 0)
[array addObjectsFromArray:[self allSubViewsForView:subView]];
计算文件大小
//文件大小
- (long long)fileSizeAtPath:(NSString *)path
NSFileManager *fileManager = [NSFileManager defaultManager];
if ([fileManager fileExistsAtPath:path])
long long size = [fileManager attributesOfItemAtPath:path error:nil].fileS
//文件夹大小
- (long long)folderSizeAtPath:(NSString *)path
NSFileManager *fileManager = [NSFileManager defaultManager];
long long folderSize = 0;
if ([fileManager fileExistsAtPath:path])
NSArray *childerFiles = [fileManager subpathsAtPath:path];
for (NSString *fileName in childerFiles)
NSString *fileAbsolutePath = [path stringByAppendingPathComponent:fileName];
if ([fileManager fileExistsAtPath:fileAbsolutePath])
long long size = [fileManager attributesOfItemAtPath:fileAbsolutePath error:nil].fileS
folderSize +=
return folderS
UIView设置部分圆角
你是不是也遇到过这样的问题,一个button或者label,只要右边的两个角圆角,或者只要一个圆角。该怎么办呢。这就需要图层蒙版来帮助我们了
CGRect rect = view.
CGSize radio = CGSizeMake(30, 30);//圆角尺寸
UIRectCorner corner = UIRectCornerTopLeft|UIRectCornerTopR//这只圆角位置
UIBezierPath *path = [UIBezierPath bezierPathWithRoundedRect:rect byRoundingCorners:corner cornerRadii:radio];
CAShapeLayer *masklayer = [[CAShapeLayer alloc]init];//创建shapelayer
masklayer.frame = view.
masklayer.path = path.CGP//设置路径
view.layer.mask =
取上整与取下整
floor(x),有时候也写做Floor(x),其功能是“下取整”,即取不大于x的最大整数 例如:
x=3.14,floor(x)=3
y=9.99999,floor(y)=9
与floor函数对应的是ceil函数,即上取整函数。
ceil函数的作用是求不小于给定实数的最小整数。
ceil(2)=ceil(1.2)=cei(1.5)=2.00
floor函数与ceil函数的返回值均为double型
计算字符串字符长度,一个汉字算两个字符
//方法一:
- (int)convertToInt:(NSString*)strtemp
int strlength = 0;
char* p = (char*)[strtemp cStringUsingEncoding:NSUnicodeStringEncoding];
for (int i=0 ; i&[strtemp lengthOfBytesUsingEncoding:NSUnicodeStringEncoding] ;i++)
p++;
strlength++;
p++;
//方法二:
-(NSUInteger) unicodeLengthOfString: (NSString *) text
NSUInteger asciiLength = 0;
for (NSUInteger i = 0; i & text. i++)
unichar uc = [text characterAtIndex: i];
asciiLength += isascii(uc) ? 1 : 2;
return asciiL
给UIView设置图片
UIImage *image = [UIImage imageNamed:@&image&];
self.MYView.layer.contents = (__bridge id _Nullable)(image.CGImage);
self.MYView.layer.contentsRect = CGRectMake(0, 0, 0.5, 0.5);
防止scrollView手势覆盖侧滑手势
[scrollView.panGestureRecognizerrequireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
去掉导航栏返回的back标题
[[UIBarButtonItemappearance]setBackButtonTitlePositionAdjustment:UIOffsetMake(0, -60)forBarMetrics:UIBarMetricsDefault];
字符串中是否含有中文
+ (BOOL)checkIsChinese:(NSString *)string
for (int i=0; i&string. i++)
unichar ch = [string characterAtIndex:i];
if (0x4E00 &= ch
&& ch &= 0x9FA5)
return YES;
return NO;
dispatch_group的使用
dispatch_group_t dispatchGroup = dispatch_group_create();
dispatch_group_enter(dispatchGroup);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@&第一个请求完成&);
dispatch_group_leave(dispatchGroup);
dispatch_group_enter(dispatchGroup);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(10 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
NSLog(@&第二个请求完成&);
dispatch_group_leave(dispatchGroup);
dispatch_group_notify(dispatchGroup, dispatch_get_main_queue(), ^(){
NSLog(@&请求完成&);
UITextField每四位加一个空格,实现代理
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:(NSRange)range replacementString:(NSString *)string
// 四位加一个空格
if ([string isEqualToString:@&&])
// 删除字符
if ((textField.text.length - 2) % 5 == 0)
textField.text = [textField.text substringToIndex:textField.text.length - 1];
return YES;
if (textField.text.length % 5 == 0)
textField.text = [NSString stringWithFormat:@&%@ &, textField.text];
return YES;
获取私有属性和成员变量 #import &objc/runtime.h&
//获取私有属性 比如设置UIDatePicker的字体颜色
- (void)setTextColor
//获取所有的属性,去查看有没有对应的属性
unsigned int count = 0;
objc_property_t *propertys = class_copyPropertyList([UIDatePicker class], &count);
for(int i = 0;i &i ++)
//获得每一个属性
objc_property_t property = propertys[i];
//获得属性对应的nsstring
NSString *propertyName = [NSString stringWithCString:property_getName(property) encoding:NSUTF8StringEncoding];
//输出打印看对应的属性
NSLog(@&propertyname = %@&,propertyName);
if ([propertyName isEqualToString:@&textColor&])
[datePicker setValue:[UIColor whiteColor] forKey:propertyName];
//获得成员变量 比如修改UIAlertAction的按钮字体颜色
unsigned int count = 0;
Ivar *ivars = class_copyIvarList([UIAlertAction class], &count);
for(int i =0;i &i ++)
Ivar ivar = ivars[i];
NSString *ivarName = [NSString stringWithCString:ivar_getName(ivar) encoding:NSUTF8StringEncoding];
NSLog(@&uialertion.ivarName = %@&,ivarName);
if ([ivarName isEqualToString:@&_titleTextColor&])
[alertOk setValue:[UIColor blueColor] forKey:@&titleTextColor&];
[alertCancel setValue:[UIColor purpleColor] forKey:@&titleTextColor&];
获取手机安装的应用
Class c =NSClassFromString(@&LSApplicationWorkspace&);
id s = [(id)c performSelector:NSSelectorFromString(@&defaultWorkspace&)];
NSArray *array = [s performSelector:NSSelectorFromString(@&allInstalledApplications&)];
for (id item in array)
NSLog(@&%@&,[item performSelector:NSSelectorFromString(@&applicationIdentifier&)]);
//NSLog(@&%@&,[item performSelector:NSSelectorFromString(@&bundleIdentifier&)]);
NSLog(@&%@&,[item performSelector:NSSelectorFromString(@&bundleVersion&)]);
NSLog(@&%@&,[item performSelector:NSSelectorFromString(@&shortVersionString&)]);
判断两个日期是否在同一周 写在NSDate的category里面
- (BOOL)isSameDateWithDate:(NSDate *)date
//日期间隔大于七天之间返回NO
if (fabs([self timeIntervalSinceDate:date]) &= 7 * 24 *3600)
return NO;
NSCalendar *calender = [NSCalendar currentCalendar];
calender.firstWeekday = 2;//设置每周第一天从周一开始
//计算两个日期分别为这年第几周
NSUInteger countSelf = [calender ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitYear forDate:self];
NSUInteger countDate = [calender ordinalityOfUnit:NSCalendarUnitWeekday inUnit:NSCalendarUnitYear forDate:date];
//相等就在同一周,不相等就不在同一周
return countSelf == countD
应用内打开系统设置界面
//iOS8之后
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:UIApplicationOpenSettingsURLString]];
//如果App没有添加权限,显示的是设定界面。如果App有添加权限(例如通知),显示的是App的设定界面。
//iOS8之前
//先添加一个url type如下图,在代码中调用如下代码,即可跳转到设置页面的对应项
[[UIApplication sharedApplication] openURL:[NSURL URLWithString:@&prefs:root=WIFI&]];
可选值如下:
About — prefs:root=General&path=About
Accessibility — prefs:root=General&path=ACCESSIBILITY
Airplane Mode On — prefs:root=AIRPLANE_MODE
Auto-Lock — prefs:root=General&path=AUTOLOCK
Brightness — prefs:root=Brightness
Bluetooth — prefs:root=General&path=Bluetooth
Date & Time — prefs:root=General&path=DATE_AND_TIME
FaceTime — prefs:root=FACETIME
General — prefs:root=General
Keyboard — prefs:root=General&path=Keyboard
iCloud — prefs:root=CASTLE
iCloud Storage & Backup — prefs:root=CASTLE&path=STORAGE_AND_BACKUP
International — prefs:root=General&path=INTERNATIONAL
Location Services — prefs:root=LOCATION_SERVICES
Music — prefs:root=MUSIC
Music Equalizer — prefs:root=MUSIC&path=EQ
Music Volume Limit — prefs:root=MUSIC&path=VolumeLimit
Network — prefs:root=General&path=Network
Nike + iPod — prefs:root=NIKE_PLUS_IPOD
Notes — prefs:root=NOTES
Notification — prefs:root=NOTIFICATI*****_ID
Phone — prefs:root=Phone
Photos — prefs:root=Photos
Profile — prefs:root=General&path=ManagedConfigurationList
Reset — prefs:root=General&path=Reset
Safari — prefs:root=Safari
Siri — prefs:root=General&path=Assistant
Sounds — prefs:root=Sounds
Software Update — prefs:root=General&path=SOFTWARE_UPDATE_LINK
Store — prefs:root=STORE
Twitter — prefs:root=TWITTER
Usage — prefs:root=General&path=USAGE
VPN — prefs:root=General&path=Network/VPN
Wallpaper — prefs:root=Wallpaper
Wi-Fi — prefs:root=WIFI
屏蔽触发事件,2秒后取消屏蔽
[[UIApplication sharedApplication] beginIgnoringInteractionEvents];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[[UIApplication sharedApplication] endIgnoringInteractionEvents]
动画暂停再开始
-(void)pauseLayer:(CALayer *)layer
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedT
-(void)resumeLayer:(CALayer *)layer
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedT
layer.beginTime = timeSinceP
fillRule原理
iOS中数字的格式化
//通过NSNumberFormatter,同样可以设置NSNumber输出的格式。例如如下代码:
NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
formatter.numberStyle = NSNumberFormatterDecimalS
NSString *string = [formatter stringFromNumber:[NSNumber numberWithInt:]];
NSLog(@&Formatted number string:%@&,string);
//输出结果为:[] Formatted number string:123,456,789
//其中NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值可以输出不同的数字格式。该枚举包括:
typedef NS_ENUM(NSUInteger, NSNumberFormatterStyle) {
NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle,
NSNumberFormatterDecimalStyle = kCFNumberFormatterDecimalStyle,
NSNumberFormatterCurrencyStyle = kCFNumberFormatterCurrencyStyle,
NSNumberFormatterPercentStyle = kCFNumberFormatterPercentStyle,
NSNumberFormatterScientificStyle = kCFNumberFormatterScientificStyle,
NSNumberFormatterSpellOutStyle = kCFNumberFormatterSpellOutStyle
//各个枚举对应输出数字格式的效果如下:其中第三项和最后一项的输出会根据系统设置的语言区域的不同而不同。
[] Formatted number string:
[] Formatted number string:123,456,789
[] Formatted number string:¥123,456,789.00
[] Formatted number string:-539,222,988%
[] Formatted number string:1.
[] Formatted number string:一亿二千三百四十五万六千七百八十九
如何获取WebView所有的图片地址,
在网页加载完成时,通过js获取图片和添加点击的识别方式
//UIWebView
- (void)webViewDidFinishLoad:(UIWebView *)webView
//这里是js,主要目的实现对url的获取
NSString * const jsGetImages =
@&function getImages(){\
var objs = document.getElementsByTagName(\&img\&);\
var imgScr = '';\
for(var i=0;i&objs.i++){\
imgScr = imgScr + objs[i].src + '+';\
return imgS\
[webView stringByEvaluatingJavaScriptFromString:jsGetImages];//注入js方法
NSString *urlResult = [webView stringByEvaluatingJavaScriptFromString:@&getImages()&];
NSArray *urlArray = [NSMutableArray arrayWithArray:[urlResult componentsSeparatedByString:@&+&]];
//urlResurlt 就是获取到得所有图片的url的拼接;mUrlArray就是所有Url的数组
//WKWebView
- (void)webView:(WKWebView *)webView didFinishNavigation:(null_unspecified WKNavigation *)navigation
NSString * const jsGetImages =
@&function getImages(){\
var objs = document.getElementsByTagName(\&img\&);\
var imgScr = '';\
for(var i=0;i&objs.i++){\
imgScr = imgScr + objs[i].src + '+';\
return imgS\
[webView evaluateJavaScript:jsGetImages completionHandler:nil];
[webView evaluateJavaScript:@&getImages()& completionHandler:^(id _Nullable result, NSError * _Nullable error) {
NSLog(@&%@&,result);
获取到webview的高度
CGFloat height = [[self.webView stringByEvaluatingJavaScriptFromString:@&document.body.offsetHeight&] floatValue];
navigationBar变为纯透明
//第一种方法
//导航栏纯透明
[self.navigationBar setBackgroundImage:[UIImage new] forBarMetrics:UIBarMetricsDefault];
//去掉导航栏底部的黑线
self.navigationBar.shadowImage = [UIImage new];
//第二种方法
[[self.navigationBar subviews] objectAtIndex:0].alpha = 0;
tabBar同理
[self.tabBar setBackgroundImage:[UIImage new]];
self.tabBar.shadowImage = [UIImage new];
navigationBar根据滑动距离的渐变色实现
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
CGFloat offsetToShow = 200.0;//滑动多少就完全显示
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToS
[[self.navigationController.navigationBar subviews] objectAtIndex:0].alpha =
- (void)scrollViewDidScroll:(UIScrollView *)scrollView
CGFloat offsetToShow = 200.0;
CGFloat alpha = 1 - (offsetToShow - scrollView.contentOffset.y) / offsetToS
[self.navigationController.navigationBar setShadowImage:[UIImage new]];
[self.navigationController.navigationBar setBackgroundImage:[self imageWithColor:[[UIColor orangeColor]colorWithAlphaComponent:alpha]] forBarMetrics:UIBarMetricsDefault];
//生成一张纯色的图片
- (UIImage *)imageWithColor:(UIColor *)color
CGRect rect = CGRectMake(0.0f, 0.0f, 1.0f, 1.0f);
UIGraphicsBeginImageContext(rect.size);
CGContextRef context = UIGraphicsGetCurrentContext();
CGContextSetFillColorWithColor(context, [color CGColor]);
CGContextFillRect(context, rect);
UIImage *theImage = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
return theI
iOS 开发中一些相关的路径
模拟器的位置:
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs
文档安装位置:
/Applications/Xcode.app/Contents/Developer/Documentation/DocSets
插件保存路径:
~/Library/ApplicationSupport/Developer/Shared/Xcode/Plug-ins
自定义代码段的保存路径:
~/Library/Developer/Xcode/UserData/CodeSnippets/
如果找不到CodeSnippets文件夹,可以自己新建一个CodeSnippets文件夹。
描述文件路径
~/Library/MobileDevice/Provisioning Profiles
navigationItem的BarButtonItem如何紧靠屏幕右边界或者左边界?
一般情况下,右边的item会和屏幕右侧保持一段距离:
下面是通过添加一个负值宽度的固定间距的item来解决,也可以改变宽度实现不同的间隔:
UIImage *img = [[UIImage imageNamed:@&icon_cog&] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal];
//宽度为负数的固定间距的系统item
UIBarButtonItem *rightNegativeSpacer = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFixedSpace target:nil action:nil];
[rightNegativeSpacer setWidth:-15];
UIBarButtonItem *rightBtnItem1 = [[UIBarButtonItem alloc]initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonItemClicked:)];
UIBarButtonItem *rightBtnItem2 = [[UIBarButtonItem alloc]initWithImage:img style:UIBarButtonItemStylePlain target:self action:@selector(rightButtonItemClicked:)];
self.navigationItem.rightBarButtonItems = @[rightNegativeSpacer,rightBtnItem1,rightBtnItem2];
NSString进行URL编码和解码
NSString *string = @&?aaa=你好&bbb=tttee&;
//编码 打印:?aaa=%E4%BD%A0%E5%A5%BD&bbb=tttee
string = [string stringByAddingPercentEncodingWithAllowedCharacters:[NSCharacterSet URLQueryAllowedCharacterSet]];
//解码 打印:?aaa=你好&bbb=tttee
string = [string stringByRemovingPercentEncoding];
UIWebView设置User-Agent。
NSDictionary *dic = @{@&UserAgent&:@&your UserAgent&};
[[NSUserDefaults standardUserDefaults] registerDefaults:dic];
NSString *agent = [self.WebView stringByEvaluatingJavaScriptFromString:@&navigator.userAgent&];
获取硬盘总容量与可用容量:
NSFileManager *fileManager = [NSFileManager defaultManager];
NSDictionary *attributes = [fileManager attributesOfFileSystemForPath:NSHomeDirectory() error:nil];
NSLog(@&容量%.2fG&,[attributes[NSFileSystemSize] doubleValue] / (powf(1024, 3)));
NSLog(@&可用%.2fG&,[attributes[NSFileSystemFreeSize] doubleValue] / powf(1024, 3));
获取UIColor的RGBA值
UIColor *color = [UIColor colorWithRed:0.2 green:0.3 blue:0.9 alpha:1.0];
const CGFloat *components = CGColorGetComponents(color.CGColor);
NSLog(@&Red: %.1f&, components[0]);
NSLog(@&Green: %.1f&, components[1]);
NSLog(@&Blue: %.1f&, components[2]);
NSLog(@&Alpha: %.1f&, components[3]);
修改textField的placeholder的字体颜色、大小
[self.textField setValue:[UIColor redColor] forKeyPath:@&_placeholderLabel.textColor&];
[self.textField setValue:[UIFont boldSystemFontOfSize:16] forKeyPath:@&_placeholderLabel.font&];
AFN移除JSON中的NSNull
AFJSONResponseSerializer *response = [AFJSONResponseSerializer serializer];
response.removesKeysWithNullValues = YES;
ceil()和floor()
ceil()功 能:返回大于或者等于指定表达式的最小整数
floor()功 能:返回小于或者等于指定表达式的最大整数
UIWebView里面的图片自适应屏幕
在webView加载完的代理方法里面这样写:
- (void)webViewDidFinishLoad:(UIWebView *)webView
NSString *js = @&function imgAutoFit() { \
var imgs = document.getElementsByTagName('img'); \
for (var i = 0; i & imgs. ++i) { \
var img = imgs[i]; \
img.style.maxWidth = %f; \
js = [NSString stringWithFormat:js, [UIScreen mainScreen].bounds.size.width - 20];
[webView stringByEvaluatingJavaScriptFromString:js];
[webView stringByEvaluatingJavaScriptFromString:@&imgAutoFit()&];
作者:iOS_小松哥
链接:/p/4523eafb4cd4#
來源:简书
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。
&&相关文章推荐
* 以上用户言论只代表其个人观点,不代表CSDN网站的观点或立场
访问:196822次
积分:2592
积分:2592
排名:第14576名
原创:78篇
转载:51篇
评论:12条
(1)(7)(1)(2)(17)(5)(3)(2)(5)(3)(3)(1)(1)(3)(2)(2)(9)(14)(5)(5)(21)(4)(4)(9)
(window.slotbydup = window.slotbydup || []).push({
id: '4740881',
container: s,
size: '200,200',
display: 'inlay-fix'

我要回帖

更多关于 listview item圆角 的文章

 

随机推荐