本文地址轉載請保留:http://www.survivalescaperooms.com/rossoneri/p/4708027.html
//from stackoverflow//nsstring to stringNSString *strA = @"NSString";std::string *strB = new std::string([strA UTF8String]);//orstd::string strB([strA UTF8String]);//string to nsstringNSString *str = [NSString stringWithCString:string.c_str() encoding:[NSString defaultCStringEncoding]];NSString *str = [NSString stringWithCString:string.c_str() encoding:NSUTF8StringEncoding]; // for chinesestd::string param; // <-- inputNSString* result = [NSString stringWithUTF8String:param.c_str()];NSString* alternative = [[NSString alloc] initWithUTF8String:param.c_str()];//chinese[NSString stringWithCString:m_AnswerSheet.GetName().c_str() encoding:NSUTF8StringEncoding]
//this removes white space from both ends of a stringNSString *newString = [oldString stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];//just wanna remove white space at the end of the string? read the link above for more detail.
std::vector<std::string> strVec;for (int i = 0; i < [NSMutableArrayObject count]; i++) { NSString *NS_Ans = (NSString *)[NSMutableArrayObject objectAtIndex:i]; std::string Str_Ans = *new std::string([NS_Ans UTF8String]); strVec.push_back(Str_Ans);}return strVec;//std::vector<std::string> ansArray = getOneVector(); NSMutableArray *nsArray = [NSMutableArray array];for (int j = 0; j < ansArray.size(); j++) { NSString *item = [NSString stringWithCString:ansArray[j].c_str() encoding:[NSString defaultCStringEncoding]]; [nsArray addObject:item];}return ansArray;
string = [NSString initWithFormat:@"%@,%@", string1, string2 ];string = [string1 stringByAppendingString:string2];string = [string stringByAppendingFormat:@"%@,%@",string1, string2];
std::string CHelpFunction::stringWithUuid() { CFUUIDRef uuidObj = CFUUIDCreate(nil); NSString *uuidString = (NSString *)CFBridgingRelease(CFUUIDCreateString(nil, uuidObj)); CFRelease(uuidObj); return [uuidString UTF8String];}
UIColor *color = [UIColor colorWithPatternImage:[UIImage imageNamed:@"bg.png"]];[myLabel setBackgroundColor:color];
UITapGestureRecognizer *singleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected)];singleTap.numberOfTapsRequired = 1;[PReArrowImage setUserInteractionEnabled:YES];[preArrowImage addGestureRecognizer:singleTap];-(void)tapDetected{ NSLog(@"single Tap on imageview"); }
[NSDictionary dictionaryWithObject:[NSNumber numberWithInt:m_quesIndex] forKey:@"index"];//geti = [[dic objectForKey:@"index"] intValue];
//sendNSNotificationCenter *nc = [NSNotificationCenter defaultCenter];NSDictionary *d = [NSDictionary dictionaryWithObject:[NSNumber numberWithInt:m_index] forKey:@"index"];[nc postNotificationName:@"viewClicked" object:self userInfo:d];//regist observer[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(viewClickAt:) name:@"quesViewClicked" object:nil];//do function- (void)quesViewClickAt:(NSNotification *)noti { int index = [[[noti userInfo] objectForKey:@"index"] intValue];}//dealloc- (void)dealloc { [[NSNotificationCenter defaultCenter] removeObserver:self];}
[view endEditing:YES];
NSArray *viewsToRemove = [self.view subviews];for (UIView *v in viewsToRemove) { [v removeFromSuperview];}
- (BOOL)textView:(nonnull UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(nonnull NSString *)text { // Prevent crashing undo bug if(range.length + range.location > textView.text.length) { return NO; } NSUInteger newLength = [textView.text length] + [text length] - range.length; return newLength <= 1024;}
if ((NSNull *)[mPages objectAtIndex:showPos] == [NSNull null]) { [mPages removeObjectAtIndex:showPos];}[mPages insertObject:mPage atIndex:showPos];[mPages removeObjectAtIndex:hidePos];[mPages insertObject:[NSNull null] atIndex:hidePos];
UPDATE FOR iOS 7[self.scrollView setContentOffset: CGPointMake(0, -self.scrollView.contentInset.top) animated:YES];ORIGINAL[self.scrollView setContentOffset:CGPointZero animated:YES];or if you want to preserve the horizontal scroll position and just reset the vertical position:[self.scrollView setContentOffset:CGPointMake(self.scrollView.contentOffset.x, 0) animated:YES];
UITextField *content = ......;//設置輸入左邊距CGRect frame = content.frame;frame.size.width = 5;UIView *leftView = [[UIView alloc] initWithFrame:frame];content.leftViewMode = UITextFieldViewModeAlways;content.leftView = leftView;
//set keyboardif (i == count - 1) [contentText setReturnKeyType:UIReturnKeyDone];else [contentText setReturnKeyType:UIReturnKeyNext];#pragma mark - TextFieldDelegate- (BOOL)textFieldShouldReturn:(nonnull UITextField *)textField { NSInteger nextTag = textField.tag + 1; // Try to find next responder UIResponder* nextResponder = [textField.superview viewWithTag:nextTag]; if (nextResponder) { // Found next responder, so set it. [nextResponder becomeFirstResponder]; } else { // Not found, so remove keyboard. [textField resignFirstResponder]; } return NO; // We do not want UITextField to insert line-breaks.}
#define SYSTEM_VERSION_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedSame)#define SYSTEM_VERSION_GREATER_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedDescending)#define SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] == NSOrderedAscending)#define SYSTEM_VERSION_LESS_THAN_OR_EQUAL_TO(v) ([[[UIDevice currentDevice] systemVersion] compare:v options:NSNumericSearch] != NSOrderedDescending)if (SYSTEM_VERSION_LESS_THAN(@"8.0")) { ...}
UIFont *textFont = [UIFont fontWithName: @"Helvetica" size: 60];UIColor *textColor = [UIColor blackColor];NSMutableParagraphStyle *textStyle = [[NSMutableParagraphStyle defaultParagraphStyle] mutableCopy];textStyle.lineBreakMode = NSLineBreakByWordWrapping;textStyle.alignment = NSTextAlignmentCenter; [textContent drawInRect:textRect withAttributes:@{NSFontAttributeName:textFont, NSForegroundColorAttributeName:textColor, NSParagraphStyleAttributeName:textStyle}];
首先可以上這個網站:http://iosfonts.com/查看自己要用的字體是否支持粗體,然后使用下面方法
-(void)boldFontForLabel:(UILabel *)label{ UIFont *currentFont = label.font; UIFont *newFont = [UIFont fontWithName:[NSString stringWithFormat:@"%@-Bold",currentFont.fontName] size:currentFont.pointSize]; label.font = newFont;}
ios 往數據庫里寫保存文件路徑的時候,不要寫全路徑,因為軟件更新或者重新安裝沙盒路徑會變
更新的流程是這樣的:更新時,先在新的路徑里安裝新程序,然后把舊程序文件夾里的配置文件之類的文件拷貝到新的路徑里去,然后刪除舊程序
所以,如果數據庫里保存的是絕對路徑,那么軟件會找不到文件。所以要保存相對路徑。比如/var/mobile/applications/ECDD1B2D-E53D-4914-BDDB-F0578BADAA38/Documents/A/B/C/9A4613EA-232A-480C-9492-B34A00BE3CB6.txt
只寫/A/B/C/9A4613EA-232A-480C-9492-B34A00BE3CB6.txt就好,前半部分用系統方法獲取。
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { UITouch *touch = [touches anyObject]; CGPoint point = [touch locationInView:self]; NSLog(@"x:%f, y:%f", point.x, point.y); if (!CGRectContainsPoint(centerView.frame, point)) { [self removeFromSuperview]; } }
UICollectionViewCell 不能用-(id)init{},要用-(id)initWithFrame:(CGRect)frame;或者initWithCoder
autolayout
[tmpView addSubview:m_textLeftTime];
[m_textLeftTime setTranslatesAutoresizingMaskIntoConstraints:NO];
[tmpView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-20-[m_imgClock]-0-[m_textLeftTime]" options:0 metrics:nil views:NSDictionaryOfVariableBindings(m_imgClock, m_textLeftTime)]];[tmpView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[tmpView]-(<=1)-[m_imgClock(==32)]" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(tmpView, m_imgClock)]];[tmpView addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:[tmpView]-(<=1)-[m_textLeftTime]" options:NSLayoutFormatAlignAllCenterY metrics:nil views:NSDictionaryOfVariableBindings(tmpView, m_textLeftTime)]];
memcmp(&(GetClientID()), &(mClientID), sizeof(mClientID)) compare unsigned char or other
新聞熱點
疑難解答