IOS一些小方法

//強(qiáng)制橫屏
AppDelegate *appdelegate=(AppDelegate *)[UIApplication sharedApplication].delegate;
appdelegate.allowRotation=YES;

//2.修改textfield的placeholder字體大小
    if (IS_IPHONE_5) {
        NSString *holderText = @"請(qǐng)輸入驗(yàn)證碼(必填)";
        NSMutableAttributedString *placeholder = [[NSMutableAttributedString alloc]initWithString:holderText];
        [placeholder addAttribute:NSForegroundColorAttributeName
                           value:[UIColor redColor]
                           range:NSMakeRange(0, holderText.length)];
        [placeholder addAttribute:NSFontAttributeName
                           value:[UIFont systemFontOfSize:12]
                           range:NSMakeRange(0, holderText.length)];
        self.authCodeField.attributedPlaceholder = placeholder;
    }
//3,label顯示兩種顏色,格式
NSString *title = [NSString stringWithFormat:@"您邀請(qǐng)的號(hào)碼(%@)已成功注冊(cè)。",model.custCode];
    titleLabel.frame = CGRectMake(15, 5, KWidth-30,30);
    titleLabel.font = [UIFont systemFontOfSize:15];
    NSMutableAttributedString *hintString=[[NSMutableAttributedString alloc]initWithString:title];
    //獲取要調(diào)整顏色的文字位置,調(diào)整顏色,range表示從第七位開(kāi)始后面11位的范圍
    [hintString addAttribute:NSForegroundColorAttributeName value:[UIColor redColor] range:NSMakeRange(7, 11)];
    titleLabel.attributedText = hintString;
//4,IOS10之后真機(jī)測(cè)試打印(打包的時(shí)候要注釋掉,否則無(wú)法打包)
#ifdef DEBUG
#define YQLString [NSString stringWithFormat:@"%s", __FILE__].lastPathComponent
#define YQLLog(...) printf(" %s\n\n", [[NSString stringWithFormat:__VA_ARGS__] UTF8String]);

#else
#define LRLog(...)
#endif
//獲取日期時(shí)間
-(void)setTimeLabelText{
    NSDate* now = [NSDate date];
    NSCalendar *cal = [NSCalendar currentCalendar];
    
    unsigned int unitFlags = NSCalendarUnitYear | NSCalendarUnitMonth | NSCalendarUnitDay | NSCalendarUnitHour | NSCalendarUnitMinute |NSCalendarUnitSecond | NSCalendarUnitWeekday;
    NSDateComponents *dd = [cal components:unitFlags fromDate:now];
    NSInteger year = [dd year];
    NSInteger mon = [dd month];
    NSInteger day = [dd day];
    
    NSInteger hour = [dd hour];
    NSInteger min = [dd minute];
    NSArray *weekdays = [NSArray arrayWithObjects: [NSNull null], @"日", @"一", @"二", @"三", @"四", @"五", @"六", nil];
    NSCalendar *calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSCalendarIdentifierGregorian];
    NSTimeZone *timeZone = [[NSTimeZone alloc] initWithName:@"Asia/Shanghai"];
    [calendar setTimeZone: timeZone];
    NSCalendarUnit calendarUnit = NSCalendarUnitWeekday;
    NSDateComponents *theComponents = [calendar components:calendarUnit fromDate:now];
    NSString *week = [weekdays objectAtIndex:theComponents.weekday];
    _timeLabel.text =[NSString stringWithFormat:@"%.2ld:%.2ld",hour,min];
    _dateLabel.text = [NSString stringWithFormat:@"%.2ld/%.2ld/%.2ld 星期%@",year,mon,day,week];

}
//坐標(biāo)從navigationbar開(kāi)始算0
   if (IS_IOS_(7)) {
        if ([self respondsToSelector:@selector(edgesForExtendedLayout)])
        {
            self.edgesForExtendedLayout = UIRectEdgeBottom;
        }
    }
//點(diǎn)擊事件穿透
- (UIView*)hitTest:(CGPoint)point withEvent:(UIEvent *)event{
    UIView *hitView = [super hitTest:point withEvent:event];
//穿透哪個(gè)就設(shè)置哪個(gè),下面這個(gè)是穿過(guò)本身view和view里面的一個(gè)子view
    if(hitView == self || hitView == _clearView){
        return nil;
    }
    return hitView;
}
//遍歷NSString
 NSString *number = _recordArray[indexPath.row];
        [number enumerateSubstringsInRange:NSMakeRange(0, number.length) options:NSStringEnumerationByComposedCharacterSequences usingBlock:^(NSString *substring, NSRange substringRange, NSRange enclosingRange, BOOL *stop) {
            NSString *order = [NSString stringWithFormat:@"button %@",substring];
            NSLog(@"=======%@",order);
//            kTCSendControlBoxCmd(order);
        }];
//代碼退出App
UIWindow *window = self.window;
            [UIView animateWithDuration:.5f animations:^{
                window.alpha = 0;
                window.frame = CGRectMake(0, -SCREENWIDTH, SCREENWIDTH, 0);
            } completion:^(BOOL finished) {
                exit(0);
            }];


最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

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