魯大師的一些工作筆記

筆記

SVN賬號 luhongwei@2016
luhw

一些方法:
計算字體高/寬度颜凯、獲取拼音方法

視圖效果:抖動動畫罢防、圓角蹲缠、陰影效果

導航欄顏色棺克、摁扭

網(wǎng)頁搜索

狀態(tài)欄顏色

調(diào)用系統(tǒng)攝像頭、圖庫吼砂、相冊

一些判斷:
定位權(quán)限逆航、攝像頭鼎文、系統(tǒng)版本渔肩、判斷設(shè)備

ios10權(quán)限

常用宏:顏色、適配拇惋、屏幕尺寸

控件:
scrollview:滑動方向周偎、隱藏滑條、某個方向的彈性

cell:cell內(nèi)數(shù)據(jù)撑帖、分割線起止位置蓉坎、注冊、選中效果

UItableview:策劃刪除胡嘿、隱藏空數(shù)據(jù)cell蛉艾、滑動到指定行

UItoolbar:彈性撐開效果

UIButton:點擊陰影效果、點擊效果衷敌、選中狀態(tài)切換

UIlable:富文本勿侯、截斷類型、居上居下顯示

UIview:增加手勢

UItextfield:添加點擊事件缴罗、純數(shù)字判斷

UITextView:添加假placeholder助琐、限制文字數(shù)量

mac指令

顯示隱藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool true

隱藏隱藏文件:

defaults write com.apple.finder AppleShowAllFiles -bool false
開啟本機服務(wù)器:

sudo apachectl -k start
sudo apachectl -k restart
顯示日歷:

cal 8 2016

不進入睡眠狀態(tài):

caffeinate -t 3600

釋放內(nèi)存:

purge

隱藏指定文件:
如果你想讓某個文件或文件夾影藏,那么chflags命令可以實現(xiàn)面氓。你只需將文件路徑填對即可兵钮,比如我們向隱藏桌面上的macx文件夾蛆橡。如果你想再次看到文件夾,只需將hidden改為nohidden即可掘譬。

chflags hidden ~/Desktop/macx

創(chuàng)建密碼保護zip:
-r 包含子文件/文件夾
-e 加密
-m 壓縮完刪除原文件
-o 設(shè)置所有被壓縮文件的最后修改時間為當前壓縮時間

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

網(wǎng)頁搜索

Markdown——入門指南

lua與oc的交互

iOS開發(fā)-動態(tài)庫加載(實時模塊更新)

iOS hybrid App 的實現(xiàn)原理及性能監(jiān)測

阿里wax框架庫

mac終端命令大全介紹

蘋果加急審核步驟

extern/static全局變量

切注

手機app通過itunes文件共享

Xcode使用快捷方式

字符串操作

歷代版本xcode等蘋果軟件

iOS圖片拉伸技巧

中間件

iOS獲取當前app的名稱和版本號

ios10 相關(guān)

qq臨時會話

交大

社保

>狀態(tài)欄顏色

1在Info.plist中設(shè)置UIViewControllerBasedStatusBarAppearance 為NO
2 在需要改變狀態(tài)欄顏色的ViewController中在ViewDidLoad方法中增加:
[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];

如果需要在全部View中都變色泰演,可以寫在父類的相關(guān)方法中,或者寫到AppDelegate中葱轩。

>判斷定位權(quán)限

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

//定位功能可用

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

//定位不能用

}

判斷是否有攝像頭

  if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){

獲取系統(tǒng)版本

[[[UIDevice currentDevice] systemVersion] floatValue];//獲取系統(tǒng)版本

>判斷版本

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

>判斷設(shè)備

-(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權(quán)限配置

一些常用的權(quán)限配置選項
// 相機
NSCameraUsageDescription
App需要您的同意,才能訪問相冊

// 相冊
NSPhotoLibraryUsageDescription
App需要您的同意,才能訪問相機

// 麥克風:
NSMicrophoneUsageDescription
App需要您的同意,才能訪問麥克風

// 通信錄
NSContactsUsageDescription
App需要您的同意,才能訪問通信錄


其它權(quán)限配置選項:

// 位置
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)]
###判斷系統(tǒng)版本
    double version = [[UIDevice currentDevice].systemVersion    doubleValue];//判定系統(tǒng)版本。

###判斷尺寸
/**  *  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;

###關(guān)閉自動布局
 self.automaticallyAdjustsScrollViewInsets = NO;
 
###系統(tǒng)獲取拼音方法
    
    //系統(tǒng)獲取首字母
- (NSString *) pinyinFirstLetter:(NSString*)sourceString {
NSMutableString *source = [sourceString mutableCopy];
CFStringTransform((__bridge CFMutableStringRef)source, NULL,    kCFStringTransformMandarinLatin, NO);
CFStringTransform((__bridge CFMutableStringRef)source, NULL, kCFStringTransformStripDiacritics, NO);//這一行是去聲調(diào)的
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"]];//發(fā)短信  

#視圖效果
### 抖動動畫

#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;
     // 動畫次數(shù)設(shè)置為最大
     anim.repeatCount = MAXFLOAT;
      // 保持動畫執(zhí)行完畢后的狀態(tài)
      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];


    


        
###批量刪除數(shù)組下標

    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;


# 系統(tǒng)攝像頭眷茁、相冊、照片
-(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內(nèi)數(shù)據(jù)
    NSIndexPath* indexpath=[NSIndexPath indexPathForRow:0 inSection:0 ];
LhwBindingAlipayCell* cell=[alipaytableview cellForRowAtIndexPath:indexpath];
####Cell分割線的設(shè)置
//分割線的長度    [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;
//系統(tǒng)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
{

// 從數(shù)據(jù)源中刪除
[dataarr removeObjectAtIndex:indexPath.row];
// 從列表中刪除
[tableView deleteRowsAtIndexPaths:@[indexPath] withRowAnimation:UITableViewRowAnimationFade];
}
###隱藏tableview空數(shù)據(jù)cell
 [self setExtraCellLineHidden:myAttentiontableview];
//隱藏空數(shù)據(jù)時候的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)];
//摁扭選中狀態(tài)切換

[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]];
        //獲取數(shù)字所在的位置
        [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);
// 對應(yīng)字號的字體一行顯示所占寬高
CGSize fontSize = [lable.text sizeWithAttributes:@{NSFontAttributeName:lable.font}];
// 多行所占 height*line
double height = fontSize.height*numberOfLines;
// 顯示范圍實際寬度
double width = self.frame.size.width;
// 對應(yīng)字號的內(nèi)容實際所占范圍
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
//設(shè)置父視圖透明纵诞,子視圖不透明
        contactbackview.backgroundColor = [UIColor colorWithWhite:0.f alpha:0.7];
        
###view增加點擊手勢
//添加手勢
UITapGestureRecognizer * tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(clickbackview)];
//將手勢添加到需要相應(yīng)的view中去
[backview addGestureRecognizer:tapGesture];
//選擇觸發(fā)事件的方式(默認單機觸發(fā))
[tapGesture setNumberOfTapsRequired:1];    


   
##UITextField
###uitextfield添加事件
[phonenumtext addTarget:self action:@selector(textFiledEditChanged:) forControlEvents:UIControlEventEditingChanged];
###UITextField 純數(shù)字判斷
#pragma mark 純數(shù)字控制
- (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限制輸入文字數(shù)量
    if (sencedestext.text.length>500) {
    sencedestext.text=[sencedestext.text substringWithRange:NSMakeRange(0, 500)];
}
最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
  • 序言:七十年代末上祈,一起剝皮案震驚了整個濱河市,隨后出現(xiàn)的幾起案子浙芙,更是在濱河造成了極大的恐慌登刺,老刑警劉巖,帶你破解...
    沈念sama閱讀 216,402評論 6 499
  • 序言:濱河連續(xù)發(fā)生了三起死亡事件嗡呼,死亡現(xiàn)場離奇詭異纸俭,居然都是意外死亡,警方通過查閱死者的電腦和手機南窗,發(fā)現(xiàn)死者居然都...
    沈念sama閱讀 92,377評論 3 392
  • 文/潘曉璐 我一進店門揍很,熙熙樓的掌柜王于貴愁眉苦臉地迎上來,“玉大人万伤,你說我怎么就攤上這事窒悔。” “怎么了壕翩?”我有些...
    開封第一講書人閱讀 162,483評論 0 353
  • 文/不壞的土叔 我叫張陵蛉迹,是天一觀的道長。 經(jīng)常有香客問我放妈,道長北救,這世上最難降的妖魔是什么荐操? 我笑而不...
    開封第一講書人閱讀 58,165評論 1 292
  • 正文 為了忘掉前任,我火速辦了婚禮珍策,結(jié)果婚禮上托启,老公的妹妹穿的比我還像新娘。我一直安慰自己攘宙,他們只是感情好屯耸,可當我...
    茶點故事閱讀 67,176評論 6 388
  • 文/花漫 我一把揭開白布。 她就那樣靜靜地躺著蹭劈,像睡著了一般疗绣。 火紅的嫁衣襯著肌膚如雪。 梳的紋絲不亂的頭發(fā)上铺韧,一...
    開封第一講書人閱讀 51,146評論 1 297
  • 那天多矮,我揣著相機與錄音,去河邊找鬼哈打。 笑死塔逃,一個胖子當著我的面吹牛,可吹牛的內(nèi)容都是我干的料仗。 我是一名探鬼主播湾盗,決...
    沈念sama閱讀 40,032評論 3 417
  • 文/蒼蘭香墨 我猛地睜開眼,長吁一口氣:“原來是場噩夢啊……” “哼立轧!你這毒婦竟也來了格粪?” 一聲冷哼從身側(cè)響起,我...
    開封第一講書人閱讀 38,896評論 0 274
  • 序言:老撾萬榮一對情侶失蹤肺孵,失蹤者是張志新(化名)和其女友劉穎匀借,沒想到半個月后,有當?shù)厝嗽跇淞掷锇l(fā)現(xiàn)了一具尸體平窘,經(jīng)...
    沈念sama閱讀 45,311評論 1 310
  • 正文 獨居荒郊野嶺守林人離奇死亡,尸身上長有42處帶血的膿包…… 初始之章·張勛 以下內(nèi)容為張勛視角 年9月15日...
    茶點故事閱讀 37,536評論 2 332
  • 正文 我和宋清朗相戀三年凳怨,在試婚紗的時候發(fā)現(xiàn)自己被綠了瑰艘。 大學時的朋友給我發(fā)了我未婚夫和他白月光在一起吃飯的照片。...
    茶點故事閱讀 39,696評論 1 348
  • 序言:一個原本活蹦亂跳的男人離奇死亡肤舞,死狀恐怖紫新,靈堂內(nèi)的尸體忽然破棺而出,到底是詐尸還是另有隱情李剖,我是刑警寧澤芒率,帶...
    沈念sama閱讀 35,413評論 5 343
  • 正文 年R本政府宣布,位于F島的核電站篙顺,受9級特大地震影響偶芍,放射性物質(zhì)發(fā)生泄漏充择。R本人自食惡果不足惜,卻給世界環(huán)境...
    茶點故事閱讀 41,008評論 3 325
  • 文/蒙蒙 一匪蟀、第九天 我趴在偏房一處隱蔽的房頂上張望椎麦。 院中可真熱鬧,春花似錦材彪、人聲如沸观挎。這莊子的主人今日做“春日...
    開封第一講書人閱讀 31,659評論 0 22
  • 文/蒼蘭香墨 我抬頭看了看天上的太陽嘁捷。三九已至,卻和暖如春显熏,著一層夾襖步出監(jiān)牢的瞬間普气,已是汗流浹背。 一陣腳步聲響...
    開封第一講書人閱讀 32,815評論 1 269
  • 我被黑心中介騙來泰國打工佃延, 沒想到剛下飛機就差點兒被人妖公主榨干…… 1. 我叫王不留现诀,地道東北人。 一個月前我還...
    沈念sama閱讀 47,698評論 2 368
  • 正文 我出身青樓履肃,卻偏偏與公主長得像仔沿,于是被迫代替她去往敵國和親。 傳聞我的和親對象是個殘疾皇子尺棋,可洞房花燭夜當晚...
    茶點故事閱讀 44,592評論 2 353

推薦閱讀更多精彩內(nèi)容