iOS 字符串
来源:互联网 发布:ubuntu如何安装输入法 编辑:程序博客网 时间:2024/06/05 12:04
- (NSString *)RMBStringWithPriceString:(NSString *)price {
NSNumberFormatter *formatter = [[NSNumberFormatteralloc] init];
NSNumber *RMBNumber = [formatter numberFromString:price];
formatter.numberStyle =NSNumberFormatterCurrencyStyle;
NSString *rmb = [formatter stringFromNumber:RMBNumber];
//$替换成¥
if ([rmb hasPrefix:@"$"]) {
rmb = [rmb stringByReplacingOccurrencesOfString:@"$"withString:@"¥"];
}
return rmb;
}
其中NSNumberFormatter类有个属性numberStyle,它是一个枚举型,设置不同的值可以输出不同的数字格式。该枚举包括:
enum {
NSNumberFormatterNoStyle = kCFNumberFormatterNoStyle,
NSNumberFormatterDecimalStyle = kCFNumberFormatterDecimalStyle,
NSNumberFormatterCurrencyStyle = kCFNumberFormatterCurrencyStyle,
NSNumberFormatterPercentStyle = kCFNumberFormatterPercentStyle,
NSNumberFormatterScientificStyle = kCFNumberFormatterScientificStyle,
NSNumberFormatterSpellOutStyle = kCFNumberFormatterSpellOutStyle
};
typedef NSUInteger NSNumberFormatterStyle;
各个枚举对应输出数字格式的效果如下:
[1243:403] Formatted number string:123456789
[1243:403] Formatted number string:123,456,789
[1243:403] Formatted number string:¥123,456,789.00
[1243:403] Formatted number string:-539,222,988%
[1243:403] Formatted number string:1.23456789E8
[1243:403] Formatted number string:一亿二千三百四十五万六千七百八十九
其中第三项和最后一项的输出会根据系统设置的语言区域的不同而不同。
NSMutableAttributedString *attString = [[NSMutableAttributedStringalloc]initWithString:@"0.00元起"];
[attString addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:30.f] range:NSMakeRange(0, textString.length -2)];
[attString addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:14.f] range:NSMakeRange(textString.length -2,2)];
NSMutableAttributedString * attrString = [[NSMutableAttributedStringalloc] initWithString:tempString];
[attrString addAttribute:NSForegroundColorAttributeNamevalue:[UIColorwhiteColor] range:NSMakeRange(0, tempString.length)];
[attrString addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:10.f] range:NSMakeRange(0, tempString.length)];
[attrString addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:6.0f] range:NSMakeRange(tempString.length -1, 1)];
[attrString addAttribute:NSBaselineOffsetAttributeNamevalue:@(5) range:NSMakeRange(tempString.length -1, 1)];
// 设置小下标
- (NSAttributedString *)makeNO2smallCount:(NSString *)str
{
NSMutableAttributedString * attrStr = [[NSMutableAttributedStringalloc] initWithString:str];
NSInteger len = str.length;
[attrStr addAttribute:NSBaselineOffsetAttributeNamevalue:@(-1)range:NSMakeRange(len-1,1)];
[attrStr addAttribute:NSFontAttributeNamevalue:[UIFontsystemFontOfSize:7.0f]range:NSMakeRange(len-1,1)];
return attrStr;
}
- ios 字符串
- ios 字符串
- iOS 字符串
- ios 字符串
- iOS字符串
- ios 字符串
- iOS 字符串
- IOS 字符串中插入字符串
- iOS字符串和可变字符串
- [iOS 字符串] 字符串后几位截取
- [IOS] ios 字符串 MD5加密
- ios 字符串的比较
- ios 操作字符串
- IOS 字符串操作
- iOS NSString截取字符串
- IOS NSString--字符串截取--
- ios 字符串排序
- ios 字符串中文乱码
- java中的static(包括类前面修饰的static、方法前面修饰的static、成员变量前面修饰的static)
- Cocos Creator 常用节点和组件接口(摘自官方文档)
- 设计人生2016网页创意设计大赛成功举办
- H5基础知识整理
- 适配器模式 Adapter Pattern
- iOS 字符串
- linux vim 命令
- objective-c之预定义
- H5:移动端触屏事件 touch
- 罪犯转移
- 将char字符转换成int整型,字符串与整型之间的相互转换
- 变态最大值
- LDA入门浅谈
- 进程组,作业与会话