nsstring

iOS: Draw NSString and border on UIImage

て烟熏妆下的殇ゞ 提交于 2019-12-10 10:36:24
问题 I am wanting to draw an NSString and a border onto a UIImage that I already have. I found a method that will draw an NSString as a UIImage, but I need it to draw on an image that I provide. -(UIImage *)imageFromText:(NSString *)text { // set the font type and size UIFont *font = [UIFont systemFontOfSize:20.0]; CGSize size = [text sizeWithFont:font]; // check if UIGraphicsBeginImageContextWithOptions is available (iOS is 4.0+) if (UIGraphicsBeginImageContextWithOptions != NULL)

Difference between “.text” and “setText:”? [duplicate]

我怕爱的太早我们不能终老 提交于 2019-12-10 10:17:41
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Is there a difference between setting a property with the dot or the bracket syntax? If I define a label in the .h file and I want to change the text of it in the .m file, is there really a difference between using label.text = @"..." and [label setText:@"..."] ? They appear to do exactly the same thing, and if that's the case, then why the different ways to do it? 回答1: There is no difference in the inner

Trouble passing Swift 4 String to Obj-C++ -[_SwiftValue dataUsingEncoding:]: unrecognized selector sent to instance

ぐ巨炮叔叔 提交于 2019-12-10 10:16:28
问题 I have some Objective-C++ code like this: // header @interface MyObjcClass - (void) myMethod: (NSString *) text; @end // implementation @implementation MyObjcClass - (void) myMethod: (NSString *) text { someInternalObject->useWstring(nsStringToWstring(text)) } std::wstring nsStringToWstring(const NSString * text) { NSData * data = [text dataUsingEncoding: NSUTF32LittleEndianStringEncoding]; // and then some other stuff irrelevant to this question return std::wstring(pointerToNewString,

How to append the following characters ‡, †, * as superscript to NSString in iOS

怎甘沉沦 提交于 2019-12-10 10:07:07
问题 I need append the following characters ‡, †, * as superscript to NSString in iOS . Need your help. I use the following http://en.wikipedia.org/wiki/General_Punctuation_(Unicode_block) link but they are appending to NSString , But i want them as superscript 回答1: Try to use this one. And you need to #import <CoreText/CTStringAttributes.h> . This code works only in iOS6 or later version. UILabel *lbl = [[UILabel alloc]initWithFrame:CGRectMake(10, 100, 200, 40)]; NSString *infoString=@"X2 and H20

iOS 获取手机型号,系统版本

蓝咒 提交于 2019-12-10 09:37:20
1.手机系统:iPhone OS NSString* phoneVersion = [[UIDevice currentDevice] systemVersion]; 2.手机类型:iPhone 6 NSString* phoneModel = [Function iphoneType];//方法在下面 3.手机系统版本:9.1 NSString * iponeM = [[UIDevice currentDevice] systemName]; 4.电池电量 CGFloat batteryLevel=[[UIDevicecurrentDevice]batteryLevel]; + (NSString *)iphoneType { 需要导入头文件:#import <sys/utsname.h> struct utsname systemInfo; uname(&systemInfo); NSString *platform = [NSString stringWithCString:systemInfo.machine encoding:NSASCIIStringEncoding]; if ([platform isEqualToString:@"iPhone1,1"]) return @"iPhone 2G"; if ([platform isEqualToString:@

Creating a NSArray from a C Array

℡╲_俬逩灬. 提交于 2019-12-10 09:30:46
问题 There are many threads about going the opposite way, but I am interested in converting from a primitive C array to a NSArray. The reason for this is that I want to create a NSString from the array contents. To create the NSString I will use: NSArray *array; NSString *stringFromArray = [array componentsJoinedByString:@","]; I am joining the elements of the array by commas because I will later be saving the string as a .csv file. I don't think it matters, but the C array I am dealing with is of

【objective-c】初次学习objective-c问题汇总... 【暂完,待修改错误】

≡放荡痞女 提交于 2019-12-10 09:21:58
---------------------------------------------------------------------------------------- 这本书,我已经看过两遍,那两遍都是在买mac pro之前看的,目的是...因为语法怪怪的很有趣。 好吧,也许还是有那么点歪心思的,现在买了电脑,第三遍看了,(⊙o⊙)…の,实践了才知道,中间会遇到这么多很纠结的问题。不过还好,速度比之前看要快很多很多了。。。 我 是分割线 终于全部实践了一次并写了一些小小的东西,不过还是不太熟练。接下来会继续看另外一本很基础的书,不过这本书就不会做笔记了,同时会跟着新买的一本口碑超赞的书进行实践练习,会有新笔记的。 这篇笔记估计不会有太多的更新了,但如果在后面的学习和回顾中发现笔记里有错误的理解和看法,会进行修改与调整的。 如果在看这篇笔记的你发现有什么问题,一定记得给我评论留言指出,O(∩_∩)O谢谢了!~ ---------------------------------------------------------------------------------------- 理解不透的问题: 1、内存管理:虽说可以自动管理内存,但是过来人说这个必须要懂,要非常懂。。。 2、类别和委托 3、NSCoding :对象的编码和解码 4、并发 5、NSPredicate

iOS创建自己本地缓存目录,截图图片存储失败问题

假装没事ソ 提交于 2019-12-10 09:12:21
1. 创建自定义目录时,fileExistsAtPath 必须判断是文件目录 /** get absolute iamge cache path @param imageName file name @return absolute path */ + (NSString *)getAbsoluteImageCachePath:(NSString *)imageName { NSString *appPackageName = [APP_INFO_DICT objectForKey:@"CFBundleIdentifier"]; NSString *md5ImageName = [self cachedFileNameForKey:imageName]; NSString *adShowImageDiskPath = [NSSearchPathForDirectoriesInDomains(NSCachesDirectory, NSUserDomainMask, true) firstObject]; NSString *adShowImageDiskDir = [adShowImageDiskPath stringByAppendingPathComponent:[NSString stringWithFormat:@"%@/CZFAdShowImages/",

iOS开发知识点装逼1:理解assign,copy,retain变strong

旧街凉风 提交于 2019-12-10 04:21:01
举个例子: NSString * houseOfMM = [[ NSString alloc ] initWithString : ' 装梵几的三室两厅 ' ]; 上面一段代码会执行以下两个动作: 1 在堆上分配一段内存用来存储@' 装梵几的三室两厅 ' ,比如:内存地址为 0X1111 内容为 ' 装梵几的三室两厅' , 2 在栈上分配一段内存用来存储 houseForWife ,比如:地址为 0XAAAA 内容自然为 0X1111 下面分别看下( assign , retain , copy ): 1.assign的情况: NSString * myHouse = [ houseOfMM assign ]; 此时 myHouse 和 hou seOfMM 完全相同,地址都是 0XAAAA ,内容为 0X1111 ,即 myHouse 只是 houseOfMM 的别名,对任何一个操作就等于对另一个操作。因此 retainCount 不需要增加.(同进同出,关系好,一把钥匙,给我拿着) 2.retain的情况: NSString * myHouse = [ houseOfMM retain ]; 此时 myHouse 的地址不再为 0XAAAA ,可能为 0XAABB ,但是内容依然为 0X1111 .因此 myHouse 和 houseOfMM 都可以管理' 装梵几的三室两厅

Remove backslash ('\') in objective-c

冷暖自知 提交于 2019-12-10 04:11:55
问题 I am generating json text and while generating array I get a lot of backslashes I don't need: [\n {\n \"Speed\" : 2,\n \"Direction\" : 3,\n \"OdometerDelta\" : 4,\n \"Longitude\" : 0,\n \"Latitude\" : 1,\n \"TimeStamp\" : \"1996-06-17\"\n },\n {\n \"Speed\" : 2,\n \"Direction\" : 3,\n \"OdometerDelta\" : 4,\n \"Longitude\" : 0,\n \"Latitude\" : 1,\n \"TimeStamp\" : \"1996-06-17\"\n },\n {\n \"Speed\" : 2,\n \"Direction\" : 3,\n \"OdometerDelta\" : 4,\n \"Longitude\" : 0,\n \"Latitude\" : 1,\n