鲁大师的一些工作笔记

笔记

SVN账号 luhongwei@2016
luhw

一些方法:
计算字体高/宽度、获取拼音方法

视图效果:抖动动画、圆角、阴影效果

导航栏颜色、摁扭

网页搜索

状态栏颜色

调用系统摄像头、图库、相册

一些判断:
定位权限、摄像头、系统版本、判断设备

ios10权限

常用宏:颜色、适配、屏幕尺寸

控件:
scrollview:滑动方向、隐藏滑条、某个方向的弹性

cell:cell内数据、分割线起止位置、注册、选中效果

UItableview:策划删除、隐藏空数据cell、滑动到指定行

UItoolbar:弹性撑开效果

UIButton:点击阴影效果、点击效果、选中状态切换

UIlable:富文本、截断类型、居上居下显示

UIview:增加手势

UItextfield:添加点击事件、纯数字判断

UITextView:添加假placeholder、限制文字数量

mac指令

显示隐藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool true

隐藏隐藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool false
开启本机服务器:

sudo apachectl -k start
sudo apachectl -k restart
显示日历:

cal 8 2016

不进入睡眠状态:

caffeinate -t 3600

释放内存:

purge

隐藏指定文件:
如果你想让某个文件或文件夹影藏,那么chflags命令可以实现。你只需将文件路径填对即可,比如我们向隐藏桌面上的macx文件夹。如果你想再次看到文件夹,只需将hidden改为nohidden即可。

chflags hidden ~/Desktop/macx

创建密码保护zip:
-r 包含子文件/文件夹
-e 加密
-m 压缩完删除原文件
-o 设置所有被压缩文件的最后修改时间为当前压缩时间

zip -e protected.zip ~/Desktop/macx.txt
文件夹:
zip -r -e 破解.zip ~/desktop/破解
直接加密:
zip -r -P 690658234 破解.zip 破解

网页搜索

Markdown——入门指南

lua与oc的交互

iOS开发-动态库加载(实时模块更新)

iOS hybrid App 的实现原理及性能监测

阿里wax框架库

mac终端命令大全介绍

苹果加急审核步骤

extern/static全局变量

切注

手机app通过itunes文件共享

Xcode使用快捷方式

字符串操作

历代版本xcode等苹果软件

iOS图片拉伸技巧

中间件

iOS获取当前app的名称和版本号

ios10 相关

qq临时会话

交大

社保

>状态栏颜色

1在Info.plist中设置UIViewControllerBasedStatusBarAppearance 为NO
2 在需要改变状态栏颜色的ViewController中在ViewDidLoad方法中增加:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

如果需要在全部View中都变色,可以写在父类的相关方法中,或者写到AppDelegate中。

>判断定位权限

if ([CLLocationManager locationServicesEnabled] && ([CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorizedWhenInUse || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusNotDetermined || [CLLocationManager authorizationStatus] == kCLAuthorizationStatusAuthorized)) {

//定位功能可用

}else if ([CLLocationManager authorizationStatus] ==kCLAuthorizationStatusDenied) {

//定位不能用

}

判断是否有摄像头

  if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){

获取系统版本

[[[UIDevice currentDevice] systemVersion] floatValue];//获取系统版本

>判断版本

NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];

>判断设备

-(NSString *)getCurrentDeviceModel
{
int mib[2];
size_t len;
char *machine;

mib[0] = CTL_HW;
mib[1] = HW_MACHINE;
sysctl(mib, 2, NULL, &len, NULL, 0);
machine = malloc(len);
sysctl(mib, 2, machine, &len, NULL, 0);

NSString *platform = [NSString stringWithCString:machine encoding:NSASCIIStringEncoding];
free(machine);
// iPhone
if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone2G";
if ([platform isEqualToString:@"iPhone1,2"]) return @"iPhone3G";
if ([platform isEqualToString:@"iPhone2,1"]) return @"iPhone3GS";
if ([platform isEqualToString:@"iPhone3,1"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone3,2"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone3,3"]) return @"iPhone4";
if ([platform isEqualToString:@"iPhone4,1"]) return @"iPhone4S";
if ([platform isEqualToString:@"iPhone5,1"]) return @"iPhone5";
if ([platform isEqualToString:@"iPhone5,2"]) return @"iPhone5";
if ([platform isEqualToString:@"iPhone5,3"]) return @"iPhone5c";
if ([platform isEqualToString:@"iPhone5,4"]) return @"iPhone5c";
if ([platform isEqualToString:@"iPhone6,1"]) return @"iPhone5s";
if ([platform isEqualToString:@"iPhone6,2"]) return @"iPhone5s";
if ([platform isEqualToString:@"iPhone7,2"]) return @"iPhone6";
if ([platform isEqualToString:@"iPhone7,1"]) return @"iPhone6Plus";
if ([platform isEqualToString:@"iPhone8,1"]) return @"iPhone6s";
if ([platform isEqualToString:@"iPhone8,2"]) return @"iPhone6sPlus";
if ([platform isEqualToString:@"iPhone8,3"]) return @"iPhoneSE";
if ([platform isEqualToString:@"iPhone8,4"]) return @"iPhoneSE";
if ([platform isEqualToString:@"iPhone9,1"]) return @"iPhone7";
if ([platform isEqualToString:@"iPhone9,2"]) return @"iPhone7Plus";

//iPod Touch
if ([platform isEqualToString:@"iPod1,1"]) return @"iPodTouch";
if ([platform isEqualToString:@"iPod2,1"]) return @"iPodTouch2G";
if ([platform isEqualToString:@"iPod3,1"]) return @"iPodTouch3G";
if ([platform isEqualToString:@"iPod4,1"]) return @"iPodTouch4G";
if ([platform isEqualToString:@"iPod5,1"]) return @"iPodTouch5G";
if ([platform isEqualToString:@"iPod7,1"]) return @"iPodTouch6G";

//iPad
if ([platform isEqualToString:@"iPad1,1"]) return @"iPad";
if ([platform isEqualToString:@"iPad2,1"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,2"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,3"]) return @"iPad2";
if ([platform isEqualToString:@"iPad2,4"]) return @"iPad2";
if ([platform isEqualToString:@"iPad3,1"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,2"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,3"]) return @"iPad3";
if ([platform isEqualToString:@"iPad3,4"]) return @"iPad4";
if ([platform isEqualToString:@"iPad3,5"]) return @"iPad4";
if ([platform isEqualToString:@"iPad3,6"]) return @"iPad4";

//iPad Air
if ([platform isEqualToString:@"iPad4,1"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad4,2"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad4,3"]) return @"iPadAir";
if ([platform isEqualToString:@"iPad5,3"]) return @"iPadAir2";
if ([platform isEqualToString:@"iPad5,4"]) return @"iPadAir2";

//iPad mini
if ([platform isEqualToString:@"iPad2,5"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad2,6"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad2,7"]) return @"iPadmini1G";
if ([platform isEqualToString:@"iPad4,4"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,5"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,6"]) return @"iPadmini2";
if ([platform isEqualToString:@"iPad4,7"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad4,8"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad4,9"]) return @"iPadmini3";
if ([platform isEqualToString:@"iPad5,1"]) return @"iPadmini4";
if ([platform isEqualToString:@"iPad5,2"]) return @"iPadmini4";

if ([platform isEqualToString:@"i386"]) return @"iPhoneSimulator";
if ([platform isEqualToString:@"x86_64"]) return @"iPhoneSimulator";
return platform;
}

IOS10权限配置

一些常用的权限配置选项
// 相机
NSCameraUsageDescription
App需要您的同意,才能访问相册

// 相册
NSPhotoLibraryUsageDescription
App需要您的同意,才能访问相机

// 麦克风:
NSMicrophoneUsageDescription
App需要您的同意,才能访问麦克风

// 通信录
NSContactsUsageDescription
App需要您的同意,才能访问通信录


其它权限配置选项:

// 位置
NSLocationUsageDescription
App需要您的同意,才能访问位置

// 在使用期间访问位置
NSLocationWhenInUseUsageDescription
App需要您的同意,才能在使用期间访问位置

// 始终访问位置
NSLocationAlwaysUsageDescription
App需要您的同意,才能始终访问位置

// 日历
NSCalendarsUsageDescription
App需要您的同意,才能访问日历

// 提醒事项
NSRemindersUsageDescription
App需要您的同意,才能访问提醒事项

// 运动与健身
NSMotionUsageDescription
App需要您的同意,才能访问运动与健身

// 健康更新
NSHealthUpdateUsageDescription
App需要您的同意,才能访问健康更新

// 健康分享
NSHealthShareUsageDescription
App需要您的同意,才能访问健康分享

// 蓝牙
NSBluetoothPeripheralUsageDescription
App需要您的同意,才能访问蓝牙

// 媒体资料库
NSAppleMusicUsageDescription
App需要您的同意,才能访问媒体资料库

##>常用宏

###颜色
define UIColorFromRGB(value,alp) [UIColor colorWithRed:((float)((value&0xFF0000)>>16))/255.0 green:((float)((value&0xFF00)>>8))/255.0 blue:((float)(value&0xFF))/255.0 alpha:alp]

//余额字体颜色
define balancegraycolor UIColorFromRGB(0x9ed8f9,1.0)
define viewbackgraycolor UIColorFromRGB(0xf1f1f1,1.0)


//屏幕适配
#define LhwRateW           (lhw_ScreenW>375?lhw_ScreenW / 375:1)//横向放大的比例,小屏不缩放,大屏按比例
#define LhwRateH           ((lhw_ScreenH<667?667:lhw_ScreenH) / 667)//竖直放大的比例,小屏不缩放,大屏按比例
#define LhwAdaptW(w)       ((w) * LhwRateW)//宽度乘以比例
#define LhwAdaptH(h)       (((h)==667&&lhw_ScreenH==480) ? 480 : ((h)*LhwRateH))
#define LhwAdaptFont(f)    ((f) * LhwRateW)
//UIScorllView 专用
#define LhwSLAdaptH(h)    (((h)==667&&lhw_ScreenH==480) ? 568: ((h)*LhwRateH))

#pragma font
#define lhw_font(fontsize) ([UIScreen mainScreen].bounds.size.height == 736) ? [UIFont systemFontOfSize:(fontsize)*LhwRateW]:[UIFont systemFontOfSize:(fontsize)]
###判断系统版本
    double version = [[UIDevice currentDevice].systemVersion    doubleValue];//判定系统版本。

###判断尺寸
/**  *  1 判断是否为3.5inch      320*480  */
define iphone4 ([UIScreen mainScreen].bounds.size.height == 480)
/**  *  2 判断是否为4inch        640*1136  */
define iphone5 ([UIScreen mainScreen].bounds.size.height == 568)
/**  *  3 判断是否为4.7inch   375*667   750*1334  */
define iphone6 ([UIScreen mainScreen].bounds.size.height == 667)
/**  *  4 判断是否为5.5inch   414*736   1242*2208  */
define iphone6p ([UIScreen mainScreen].bounds.size.height == 736)



###中心center
arrowimage2.center=hasreleasetaskimage.center;
CGRect arrowimage2tmp=arrowimage2.frame;
arrowimage2tmp.origin.x+=305;
arrowimage2.frame=arrowimage2tmp;







###全局变量
extern NSString* meString;



#一些方法:
###计算字体高度、宽度
CGSize resultSize = [data.Commoditydetailstr boundingRectWithSize:CGSizeMake(1000, 40) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:_lhw_font(14)} context:nil].size;

###关闭自动布局
 self.automaticallyAdjustsScrollViewInsets = NO;
 
###系统获取拼音方法
    
    //系统获取首字母
- (NSString *) pinyinFirstLetter:(NSString*)sourceString {
NSMutableString *source = [sourceString mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)source, NULL,    kCFStringTransformMandarinLatin, NO);
CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);//这一行是去声调的
return source;
}

##电话、短信
//拨打电话 没有弹窗
    NSString *num = [[NSString alloc] initWithFormat:@"tel://%@",_phonenumlab.text]; [[UIApplication sharedApplication] openURL:[NSURL URLWithString:num]];
    //电话有弹窗

UIWebView*callWebview =[[UIWebView alloc] init];  
NSURL *telURL =[NSURL URLWithString:@"tel:10010"];  
[callWebview loadRequest:[NSURLRequest requestWithURL:telURL]];  
//记得添加到view上  
[self.view addSubview:callWebview];  

//短信

[[UIApplication sharedApplication]openURL:[NSURL URLWithString:@"sms://10010"]];//发短信  

#视图效果
### 抖动动画

#pragma mark - 抖动动画
#define Angle2Radian(angle) ((angle) / 180.0 * M_PI)
- (void)shakingAnimation {
anim = [CAKeyframeAnimation animation];
 anim.keyPath = @"transform.rotation";
  anim.values = @[@(Angle2Radian(-4)), @(Angle2Radian(4)), @(Angle2Radian(-4))];
  anim.duration = 0.2;
     // 动画次数设置为最大
     anim.repeatCount = MAXFLOAT;
      // 保持动画执行完毕后的状态
      anim.removedOnCompletion = NO;
       anim.fillMode = kCAFillModeForwards;
        [self.layer addAnimation:anim forKey:@"shake"];
}
-(void)stopshak:(UIButton*)sender{
    [self.layer removeAllAnimations];
}

###圆角
 userhead.layer.masksToBounds = YES;  
userhead.layer.cornerRadius = 6.0;  
userhead.layer.borderWidth = 1.0;  
userhead.layer.borderColor = [[UIColor whiteColor] CGColor];

###指定角的圆角
    UIBezierPath *maskPath = [UIBezierPath        bezierPathWithRoundedRect:addremin.bounds byRoundingCorners:UIRectCornerBottomLeft | UIRectCornerBottomRight cornerRadii:CGSizeMake(5, 5)];
CAShapeLayer *maskLayer = [[CAShapeLayer alloc] init];
maskLayer.frame = addremin.bounds;
maskLayer.path = maskPath.CGPath;
addremin.layer.mask = maskLayer;
    
###视图增加阴影效果
 //加阴影
savebut.layer.shadowColor = lhw_4ecb7b_greencolor.CGColor;//shadowColor阴影颜色
savebut.layer.shadowOffset = CGSizeMake(0,4);//shadowOffset阴影偏移,x向右偏移4,y向下偏移4,默认(0, -3),这个跟shadowRadius配合使用
savebut.layer.shadowOpacity = 0.8;//阴影透明度,默认0
savebut.layer.shadowRadius = 7;//阴影半径,默认3

###导航栏背景颜色增加摁扭
UIButton* rightBun = [UIButton buttonWithType:UIButtonTypeCustom];
rightBun.frame = CGRectMake(0, 0, 55, 30);
[rightBun setTitle:@"新增" forState:UIControlStateNormal];
[rightBun addTarget:self action:@selector(additioncontact) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* right = [[UIBarButtonItem alloc] initWithCustomView:rightBun];
self.navigationItem.rightBarButtonItem = right;
NSArray *rightButtons=@[right];
self.navigationItem.rightBarButtonItems= rightButtons;
//导航栏背景颜色
self.navigationController.navigationBar.barTintColor=[UIColor redColor];


    


        
###批量删除数组下标

    view.mutabletextarr removeObjectsAtIndexes:<#(nonnull NSIndexSet *)#>
#导航栏

//导航栏字体、颜色

self.title=@"收到";
self.navigationController.navigationBar.titleTextAttributes = @{UITextAttributeTextColor: lhw_3b9dfe_3b9dfecolor, UITextAttributeFont : [UIFont boldSystemFontOfSize:18]};

//导航栏增加摁扭

    UIButton* rightBun = [UIButton buttonWithType:UIButtonTypeCustom];
rightBun.frame = CGRectMake(0, 0, 55, 30);
[rightBun setTitle:@"新增" forState:UIControlStateNormal];
[rightBun addTarget:self action:@selector(additioncontact) forControlEvents:UIControlEventTouchUpInside];
UIBarButtonItem* right = [[UIBarButtonItem alloc] initWithCustomView:rightBun];
self.navigationItem.rightBarButtonItem = right;
NSArray *rightButtons=@[right];
self.navigationItem.rightBarButtonItems= rightButtons;


# 系统摄像头、相册、照片
-(void)selectedImageForIcon
{

UIAlertController *alertController=[UIAlertController alertControllerWithTitle:@"" message:@"" preferredStyle:UIAlertControllerStyleActionSheet];
UIAlertAction *actionCamera=[UIAlertAction actionWithTitle:@"打开相机" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypeCamera;
//        [UIImagePickerController availableCaptureModesForCameraDevice:UIImagePickerControllerCameraDeviceFront];
   myaccount.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;//前摄像头
    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *actionPhotoLIbrary=[UIAlertAction actionWithTitle:@"打开相册" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;

    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *actionPhotoAlbum=[UIAlertAction actionWithTitle:@"打开图库" style:UIAlertActionStyleDefault handler:^(UIAlertAction * _Nonnull action) {

    myaccount.imagePicker.sourceType=UIImagePickerControllerSourceTypeSavedPhotosAlbum;
    [self presentViewController:myaccount.imagePicker animated:YES completion:nil];

}];

UIAlertAction *cancelAction=[UIAlertAction actionWithTitle:@"取消" style:UIAlertActionStyleCancel handler:nil];

[alertController addAction:actionCamera];

[alertController addAction:actionPhotoAlbum];

[alertController addAction:actionPhotoLIbrary];

[alertController addAction:cancelAction];
alertController.isShowNavBars = YES;
[self presentViewController:alertController animated:YES completion:nil];

}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(nullable NSDictionary *)editingInfo
{

//    _selectedRightImage.image=image;
[myaccount.headimage setImage:image forState:UIControlStateNormal];

[self dismissViewControllerAnimated:YES completion:nil];

}

#++++++++++++++++++++++++++++++++++++++++++


#控件

#scrollview

###判断scrollview的滑动方向

-(void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
historyY = scrollView.contentOffset.y;
}
-(void)scrollViewDidScroll:(UIScrollView *)scrollView {
  if (scrollView.contentOffset.yhistoryY) {
    NSLog(@"向上");

    }
###scrollview隐藏滑动条
webview.scrollView.showsVerticalScrollIndicator = FALSE;
webview.scrollView.showsHorizontalScrollIndicator = FALSE;

###scrollview某个方向去除弹性效果

  scrollView.bounces = (scrollView.contentOffset.y <= 0) ? NO : YES;


##Cell
##获取cell内数据
    NSIndexPath* indexpath=[NSIndexPath indexPathForRow:0 inSection:0 ];
LhwBindingAlipayCell* cell=[alipaytableview cellForRowAtIndexPath:indexpath];
####Cell分割线的设置
//分割线的长度    [lhwcell setSeparatorInset:UIEdgeInsetsMake(0, 10, 0, 10)];
 去除分割线:  self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;

 //cell自定义起止位置
 - (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {
UIEdgeInsets tmp =UIEdgeInsetsMake(0,11.5, 0, 10);

if ([tableView respondsToSelector:@selector(setLayoutMargins:)]) {
    [tableView setLayoutMargins:tmp];
    [cell setLayoutMargins:tmp];
}
if ([tableView respondsToSelector:@selector(setSeparatorInset:)]) {
    [tableView setSeparatorInset:tmp];
    [cell setSeparatorInset:tmp];
}
}
###cell注册
//自定义cell
    [myTrackingtableview registerClass:[LhwMyTrackingCell class] forCellReuseIdentifier:@"LhwMyTrackingCell"];
       LhwMyTrackingCell* lhwcell = [tableView dequeueReusableCellWithIdentifier:@"LhwMyTrackingCell" forIndexPath:indexPath];
lhwcell.selectionStyle = UITableViewCellSelectionStyleNone;
//系统cell
        UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"lhwcell"];
if (cell == nil) {
    cell = [[UITableViewCell alloc] initWithStyle:UITableViewCellStyleSubtitle reuseIdentifier:@"lhwcell"] ;
}
****
###取消cell选中效果
lhwcell.selectionStyle = UITableViewCellSelectionStyleNone;


##UItableview
###tableview 策划删除

- (BOOL)tableView:(UITableView *)tableView canEditRowAtIndexPath:(NSIndexPath *)indexPath
{
return YES;
}
- (NSString *)tableView:(UITableView *)tableView titleForDeleteConfirmationButtonForRowAtIndexPath:(NSIndexPath *)indexPath
{
return @"删除";
}
- (void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath
{

// 从数据源中删除
[dataarr removeObjectAtIndex:indexPath.row];
// 从列表中删除
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
###隐藏tableview空数据cell
 [self setExtraCellLineHidden:myAttentiontableview];
//隐藏空数据时候的tableviewcell线
    -(void)setExtraCellLineHidden: (UITableView *)tableView
{
   UIView *view = [UIView new];
   view.backgroundColor = [UIColor clearColor];
 [tableView setTableFooterView:view];
}

###tableview滑动到指定行
[table scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:arr.count+1 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

     
###toolbar 中的弹簧撑开效果
                UIBarButtonItem* but=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(cancelchoice)];
        [but setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName, nil] forState:UIControlStateNormal];

        UIBarButtonItem* butright=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemDone target:self action:@selector(cancelchoice)];
        [butright setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIFont boldSystemFontOfSize:14], NSFontAttributeName, nil] forState:UIControlStateNormal];

        UIBarButtonItem *btn4=[[UIBarButtonItem alloc]initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:self action:nil];

        UIToolbar*  toolBar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0, 0 ,lhw_ScreenW, 25)];
        [toolBar setBarStyle:UIBarStyleDefault];
        toolBar.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin;
        [toolBar setItems:[NSArray arrayWithObjects:but,btn4,butright,nil]];
        [choiceview addSubview:toolBar];

  
##UIButton

//摁扭的点击时候的阴影效果

      button.adjustsImageWhenHighlighted = NO;
//摁扭上的图片与周边间距

       [button.setImageEdgeInsets:UIEdgeInsetsMake(5, 5, 5, 5)];
//摁扭选中状态切换

[but setImage:[UIImage imageNamed:@"1.jpg"] forState:UIControlStateNormal];
[but setImage:[UIImage imageNamed:@"1.jpg"] forState: UIControlStateHighlighted];
[but setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateSelected];
[but setImage:[UIImage imageNamed:@"2.png"] forState:UIControlStateSelected | UIControlStateHighlighted];
[but addTarget:self action:@selector(buttonClick:)    forControlEvents:UIControlEventTouchUpInside];

- (void)buttonClick:(UIButton *)sender {
sender.selected = !sender.selected;
NSLog(@"%d",sender.selected);
}



    
##UILable
##富文本
 NSMutableAttributedString *attrString = [[NSMutableAttributedString alloc] initWithString:[NSString stringWithFormat:@"获得%d积分",countbum]];
        //获取数字所在的位置
        [prizeinformationlab.text rangeOfString:[NSString stringWithFormat:@"%d",countbum]];
        NSRange ranegtmp=[strtmp rangeOfString:[NSString stringWithFormat:@"%d",countbum]];
        [attrString addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Impact" size:36] range:ranegtmp];
        prizeinformationlab.attributedText=attrString;


##Lable截断类型
_waringdeslab.lineBreakMode=NSLineBreakByCharWrapping;//字符截断
###Lable居上显示
#pragma mark 居上显示
-(void)alignTop:(UILabel*)lable
{
NSLog(@"%@",lable.font);
// 对应字号的字体一行显示所占宽高
CGSize fontSize = [lable.text sizeWithAttributes:@{NSFontAttributeName:lable.font}];
// 多行所占 height*line
double height = fontSize.height*numberOfLines;
// 显示范围实际宽度
double width = self.frame.size.width;
// 对应字号的内容实际所占范围
CGSize stringSize = [lable.text boundingRectWithSize:CGSizeMake(width, height) options:(NSStringDrawingUsesLineFragmentOrigin) attributes:@{NSFontAttributeName:lable.font} context:nil].size;
// 剩余空行
NSInteger line = (height - stringSize.height) / fontSize.height;
// 用回车补齐
for (int i = 0; i < line; i++) {
    lable.text = [lable.text stringByAppendingString:@"\n "];
}
}

###Lable居下显示
#pragma mark居下显示
-(void)alignBottom  
{  
CGSize fontSize = [self.text sizeWithAttributes:@{NSFontAttributeName:self.font}];  
double height = fontSize.height*self.numberOfLines;  
double width = self.frame.size.width;  
CGSize stringSize = [self.text boundingRectWithSize:CGSizeMake(width, height) options:NSStringDrawingUsesLineFragmentOrigin attributes:@{NSFontAttributeName:self.font} context:nil].size;  

NSInteger line = (height - stringSize.height) / fontSize.height;  
// 前面补齐换行符  
for (int i = 0; i < line; i++) {  
    self.text = [NSString stringWithFormat:@" \n%@", self.text];  
}  
}    

    
###UIView
//设置父视图透明,子视图不透明
        contactbackview.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];
        
###view增加点击手势
//添加手势
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickbackview)];
//将手势添加到需要相应的view中去
[backview addGestureRecognizer:tapGesture];
//选择触发事件的方式(默认单机触发)
[tapGesture setNumberOfTapsRequired:1];    


   
##UITextField
###uitextfield添加事件
[phonenumtext addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
###UITextField 纯数字判断
#pragma mark 纯数字控制
- (BOOL)textField:(UITextField *)textField shouldChangeCharactersInRange:    (NSRange)range replacementString:(NSString *)string {
return [self validateNumber:string];
    }
- (BOOL)validateNumber:(NSString*)number {
BOOL res = YES;
NSCharacterSet* tmpSet = [NSCharacterSet characterSetWithCharactersInString:@"0123456789"];
int i = 0;
while (i < number.length) {
    NSString * string = [number substringWithRange:NSMakeRange(i, 1)];
    NSRange range = [string rangeOfCharacterFromSet:tmpSet];
    if (range.length == 0) {
        res = NO;
        break;
    }
    i++;
}
return res;
}  

##UITextView
###UITextView假placehold
    placehoderlab=[[UILabel alloc]initWithFrame:CGRectMake(5,5+2, 170, 20)];
[sencedestext addSubview:placehoderlab];
placehoderlab.text=@"请输入您的需求";
placehoderlab.font=lhw_font(15);
placehoderlab.textColor=lhw_cccccc_graycolor;

#pragma mark textview代理
- (void)textViewDidBeginEditing:(UITextView *)textView {
if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}
}

- (void)textViewDidEndEditing:(UITextView *)textView {
if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}
}

-(void)textViewDidChange:(UITextView *)textView{

if (sencedestext.text.length<1) {
    placehoderlab.hidden=NO;
}else{
    placehoderlab.hidden=YES;
}

}

###UITextView限制输入文字数量
    if (sencedestext.text.length>500) {
    sencedestext.text=[sencedestext.text substringWithRange:NSMakeRange(0, 500)];
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 194,088评论 5 459
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 81,715评论 2 371
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 141,361评论 0 319
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 52,099评论 1 263
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 60,987评论 4 355
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 46,063评论 1 272
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 36,486评论 3 381
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 35,175评论 0 253
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 39,440评论 1 290
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 34,518评论 2 309
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 36,305评论 1 326
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 32,190评论 3 312
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 37,550评论 3 298
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 28,880评论 0 17
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 30,152评论 1 250
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 41,451评论 2 341
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 40,637评论 2 335

推荐阅读更多精彩内容