iOS - 富文本

iOS--NSAttributedString超全属性详解及应用(富文本、图文混排)

ios项目中经常需要显示一些带有特殊样式的文本,比如说带有下划线、删除线、斜体、空心字体、背景色、阴影以及图文混排(一种文字中夹杂图片的显示效果)。通常想要实现这些效果要使用到iOS的Foundation框架提供的NSAttributedString类,NSAttributedString类中有许多属性,不同属性对应不同的文本样式。本文主要对这些属性做一个解释说明,并会结合实际代码来应用它们。

1. NSAttributedString属性概览表

keyvalue说明
NSFontAttributeNameUIFont对象字体大小:默认Helvetica(Neue) 12
NSParagraphStyleAttributeNameNSParagraphStyle对象文本字、行间距,对齐等:默认defaultParagraphStyle
NSForegroundColorAttributeNameUIColor对象字体颜色:默认blackColor
NSBackgroundColorAttributeNameUIColor对象背景色:默认nil(无背景色)
NSLigatureAttributeName包含整数的NSNumber对象连字符:ios中有0和1两个值;0表示没有连字符,而1是默认的连字符
NSKernAttributeName包含浮点数的NSNumber对象字符间距:默认0(禁用)
NSStrikethroughStyleAttributeName包含整数的NSNumber对象删除线:默认0(无删除线)
NSUnderlineStyleAttributeName包含整数的NSNumber对象下划线:默认0(无下划线)
NSStrikethroughColorAttributeNameUIColor对象删除线颜色:默认 nil(和文字的 foregroundColor一致)
NSUnderlineColorAttributeNameUIColor对象下划线颜色:默认nil(和文字的 foregroundColor一致)
NSStrokeColorAttributeNameUIColor对象描边颜色:nil(和文字的 foregroundColor一致)
NSStrokeWidthAttributeName包含浮点数的NSNumber对象描边宽度:正值空心描边,负值实心描边,默认0(不描边)
NSShadowAttributeNameNSShadow对象文本阴影:默认nil(没有阴影)
NSTextEffectAttributeNameNSString对象文字效果:默认nil(没有文字效果)
NSAttachmentAttributeNameNSTextAttachment对象附件(常用作图文混排) :默认nil(没有附件)
NSLinkAttributeNameNSURL (优先) 或 NSString对象链接
NSBaselineOffsetAttributeName包含浮点数的NSNumber对象基础偏移量:正值向上偏移,负值向下偏移,默认0(不偏移)
NSObliquenessAttributeName包含浮点数的NSNumber对象字体倾斜 :正值向右倾斜,负值向左倾斜, 默认0(不倾斜)
NSExpansionAttributeName包含浮点数的NSNumber对象文本扁平化:正值横向拉伸,负值横向压缩,默认0(不拉伸)

2. 属性详解及应用(图文混排比较特殊,会在第 3 部分单独说明)

NSMutableAttributedString 是 NSAttributedString 的子类,一般来说我比较习惯使用NSMutableAttributedString来实现富文本,本文的例子也是采用NSMutableAttributedString来实现的,与NSAttributedString实现效果相比并无优缺点之分,主要目的是讲清楚这些属性。

本文使用NSMutableAttributedString实现富文本,主要步骤分为以下三步,为避免下面解释代码时所添加的注释不断重复,特在此说明提前说明一下:

  • 调用 - (instancetype)initWithString:(NSString *)str 方法来创建 NSMutableAttributedString 实例
  • 调用 - (void)addAttribute:(NSString *)name value:(id)value range:(NSRange)range 方法添加所需的 Attribute 属性,要注意range的范围,所添加的属性只对指定范围内的文字有效
  • 给 label 赋值 : label.attributedText = attributedString;

2.1 NSFontAttributeName —— 字体大小

代码 :

- (void)fontAttributeNameTest {NSString *text = @"我是30号系统字体,你是15号Courier-BoldOblique字体";// 1.创建NSMutableAttributedString实例NSMutableAttributedString *fontAttributeNameStr = [[NSMutableAttributedString alloc]initWithString:text]; // 2.添加属性 [fontAttributeNameStr addAttribute:NSFontAttributeName value:[UIFont systemFontOfSize:30] range:NSMakeRange(0, 9)]; [fontAttributeNameStr addAttribute:NSFontAttributeName value:[UIFont fontWithName:@"Courier-BoldOblique" size:15] range:NSMakeRange(9, text.length - 9)]; // 3.给label赋值 self.label.attributedText = fontAttributeNameStr; } 

效果图 :


NSFontAttributeName.png

2.2 NSParagraphStyleAttributeName —— 文本字、行间距,对齐等

代码:

- (void)paragraphStyleAttributeNameTest {NSString *text = @"我是一个很长很长很长的文本,我的字间距是5,行间距是20,对齐方式为居中对齐。";NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:text]; // 创建NSMutableParagraphStyle实例 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = 5; //字间距5 paragraphStyle.paragraphSpacing = 20; //行间距是20 paragraphStyle.alignment = NSTextAlignmentCenter; //对齐方式为居中对齐 [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, text.length)]; self.label.attributedText = attributeStr; } 

效果图:

NSParagraphStyleAttributeName.png

2.3 NSForegroundColorAttributeName —— 字体颜色

代码:

- (void)foregroundColorAttributeNameTest {NSString *text = @"你好呀,我默认颜色是label的textColor,但是我现在要通过NSForegroundColorAttributeName属性变成一个蓝色了,看好喽!";NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:text]; [attributeStr addAttribute:NSForegroundColorAttributeName value:[UIColor blueColor] range:NSMakeRange(26, text.length - 26)]; self.label.attributedText = attributeStr; } 

效果图:

NSForegroundColorAttributeName.png

2.4 NSBackgroundColorAttributeName —— 背景色

代码:

- (void)backgroundColorAttributeNameTest {NSString *text = @"我是一个紫色背景色的文本!";NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:text]; [attributeStr addAttribute:NSBackgroundColorAttributeName value:[UIColor purpleColor] range:NSMakeRange(0, text.length)]; self.label.attributedText = attributeStr; } 

效果图:

NSBackgroundColorAttributeName.png

2.5 NSLigatureAttributeName —— 连字符

ios 中有 0 和 1 两个值:0表示没有连字符,而1是默认的连字符。(一般对连笔写的英文有效, 中文即使设置了连字符也很难表现出来)。

代码:

- (void)ligatureAttributeNameTest {NSString *text = @"逗号前面的我是一个没有连字符样式的fl,逗号后面的你是一个带连字符样式的fl(你看后半句的汉字连字符样式好难体现出来哦)";NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:text]; [attributeStr addAttribute:NSFontAttributeName value:[UIFont fontWithName: @"futura" size: 20] range:NSMakeRange(0, text.length)]; // 设置文本前半句无连字符效果 [attributeStr addAttribute:NSLigatureAttributeName value:[NSNumber numberWithInt:0] range:NSMakeRange(0, 19)]; // 设置文本后半句有连字符效果 [attributeStr addAttribute:NSLigatureAttributeName value:[NSNumber numberWithInt:1] range:NSMakeRange(19, text.length - 19)]; self.label.attributedText = attributeStr; } 

效果图:

NSLigatureAttributeName.png

2.6 NSKernAttributeName —— 字符间距

注意: 正值间距加宽,负值间距变窄,0表示默认效果

代码:

- (void)kernAttributeNameTest {NSString *text = @"设置我的字间距为正值20有拉大效果,中间的你是正常效果,设置他的字间距为负值-5有减少效果";NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc]initWithString:text]; [attributeStr addAttribute:NSKernAttributeName value:@20 range:NSMakeRange(0, 18)]; [attributeStr addAttribute:NSKernAttributeName value:@(-5) range:NSMakeRange(28, text.length - 28)]; self.label.attributedText = attributeStr; } 

效果图:

NSKernAttributeName.png
----------------------------写在设置文本的删除线和下划线之前----------------------

删除线和下划线的区别就是:删除线是在文字中间显示,下划线是在文字的底部显示;除这一点外,设置的可选值是一样的,都是NSUnderlineStyle的枚举常量

    NSUnderlineStyleNone                                    = 0x00,NSUnderlineStyleSingle                                  = 0x01,NSUnderlineStyleThick NS_ENUM_AVAILABLE(10_0, 7_0) = 0x02, NSUnderlineStyleDouble NS_ENUM_AVAILABLE(10_0, 7_0) = 0x09, NSUnderlinePatternSolid NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0000, NSUnderlinePatternDot NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0100, NSUnderlinePatternDash NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0200, NSUnderlinePatternDashDot NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0300, NSUnderlinePatternDashDotDot NS_ENUM_AVAILABLE(10_0, 7_0) = 0x0400, NSUnderlineByWord NS_ENUM_AVAILABLE(10_0, 7_0) = 0x8000 

在 2.7 中会对他们进行一个统一说明。

--------------------------------------------------------------------------------------------------

2.7 NSStrikethroughStyleAttributeName —— 删除线NSStrikethroughColorAttributeName —— 删除线颜色NSUnderlineStyleAttributeName —— 下划线NSUnderlineColorAttributeName —— 下划线颜色

代码:

- (void)strikethroughStyleAndUnderlineStyleTest {NSArray *textArr = @[@"NSUnderlineStyleNone样式", @"NSUnderlineStyleSingle样式", @"NSUnderlineStyleThick样式", @"NSUnderlineStyleDouble样式"]; NSArray *colorArr = @[[UIColor blueColor], [UIColor redColor], [UIColor purpleColor], [UIColor whiteColor]]; NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] init]; //依次为每个字符串数组中的字符添加不同样式和不同颜色的删除线、下划线 for (int i = 0; i < textArr.count; i++) { NSMutableAttributedString *singleAttributeStr = [[NSMutableAttributedString alloc]initWithString:textArr[i]]; //设置删除线样式 [singleAttributeStr addAttribute:NSStrikethroughStyleAttributeName value:@(i) range:NSMakeRange(0, ((NSString *)textArr[i]).length)]; //设置删除线颜色 [singleAttributeStr addAttribute:NSStrikethroughColorAttributeName value:colorArr[i] range:NSMakeRange(0, ((NSString *)textArr[i]).length)]; //设置下划线样式 [singleAttributeStr addAttribute:NSUnderlineStyleAttributeName value:@(i) range:NSMakeRange(0, ((NSString *)textArr[i]).length)]; //设置下划线颜色 [singleAttributeStr addAttribute:NSUnderlineColorAttributeName value:colorArr[i] range:NSMakeRange(0, ((NSString *)textArr[i]).length)]; [attributeStr appendAttributedString:singleAttributeStr]; } self.label.attributedText = attributeStr; } 

效果图:

删除线和下划线.png

2.8 NSStrokeColorAttributeName —— 描边颜色NSStrokeWidthAttributeName —— 描边宽度

注意事项:
  • 描边颜色要搭配非0的描边宽度才会生效,如果只设置了描边颜色,描边宽度为0,则没有描边效果
  • 描边宽度是正数,会对文字进行描边,但文字中心不填充( 一种经典的空心文本样式是在该值为3.0)
  • 描边宽度是负数,会对文字进行描边,而且会同时对文字中心进行填充(填充的颜色为文字本来的字体颜色)

代码:

- (void)strokeTest {// 给第一个label只设置描边颜色NSString *text1 = @"只设置描边颜色,没有设置描边宽度(默认为0),没有效果";NSMutableAttributedString *attributeStr1 = [[NSMutableAttributedString alloc] initWithString:text1 ]; [attributeStr1 addAttribute:NSStrokeColorAttributeName value:[UIColor blueColor] range:NSMakeRange(0, text1.length)]; self.label1.attributedText = attributeStr1; // 给第二个label设置描边宽度为正数3,不设置描边颜色 NSString *text2 = @"将描边宽度设置为正数3,无描边颜色,具有空心效果哦,此时描边颜色默认成字体本来的颜色!"; NSMutableAttributedString *attributeStr2 = [[NSMutableAttributedString alloc] initWithString:text2 ]; [attributeStr2 addAttribute:NSStrokeWidthAttributeName value:@(3) range:NSMakeRange(0, text2.length)]; self.label2.attributedText = attributeStr2; // 给第三个label设置描边宽度为正数3,描边颜色为红色 NSString *text3 = @"将描边宽度设置为正数3,描边颜色为红色,具有空心效果哦,因为正数不对文字内部进行填充!"; NSMutableAttributedString *attributeStr3 = [[NSMutableAttributedString alloc] initWithString:text3 ]; [attributeStr3 addAttribute:NSStrokeColorAttributeName value:[UIColor redColor] range:NSMakeRange(0, text3.length)]; [attributeStr3 addAttribute:NSStrokeWidthAttributeName value:@(3) range:NSMakeRange(0, text3.length)]; self.label.attributedText = attributeStr3; // 给第四个label设置描边宽度为负数-3,描边颜色为紫色 NSString *text4 = @"将描边宽度设置为负数-3,又设置描边颜色,无空心效果,因为负数会对文字内部进行填充!"; NSMutableAttributedString *attributeStr4 = [[NSMutableAttributedString alloc] initWithString:text4 ]; [attributeStr4 addAttribute:NSStrokeColorAttributeName value:[UIColor purpleColor] range:NSMakeRange(0, text4.length)]; [attributeStr4 addAttribute:NSStrokeWidthAttributeName value:@(-3) range:NSMakeRange(0, text4.length)]; self.label3.attributedText = attributeStr4; } 

效果图:

描边.png

2.9 NSShadowAttributeName —— 文本阴影

代码:

- (void)shadowTest {NSString *text = @"一个有阴影的文本!";NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; // 创建NSShadow实例 NSShadow *shadow = [[NSShadow alloc] init]; shadow.shadowColor = [UIColor purpleColor]; shadow.shadowBlurRadius = 3.0; shadow.shadowOffset = CGSizeMake(0, 0.8); // 添加属性 [attributeStr addAttribute:NSShadowAttributeName value:shadow range:NSMakeRange(0, text.length)]; self.label.attributedText = attributeStr; } 

效果图:

NSShadowAttributeName.png

2.10 NSTextEffectAttributeName —— 文字效果

代码:

- (void)textEffectAttributeTest {NSString *text = @"我是没有文字效果的,你是有文字效果的!";NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; [attributeStr addAttribute:NSTextEffectAttributeName value:NSTextEffectLetterpressStyle range:NSMakeRange(10, text.length - 10)]; self.label.attributedText = attributeStr; } 

效果图:

NSTextEffectAttributeName.png

2.11 NSLinkAttributeName —— 链接

注意:UILabel无法使用该属性, 但UITextView 控件可以使用,所以下面关于 NSLinkAttributeName 属性的代码也是使用 UITextView 来测试的。

代码:

// 注意:跳转链接要实现UITextView的这个委托方法
- (BOOL)textView:(UITextView *)textView shouldInteractWithURL:(NSURL *)url inRange:(NSRange)characterRange { return YES; } - (void)linkAttributeTest { NSString *text = @"点我跳转到百度哦!"; NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"]; [attributeStr addAttribute:NSLinkAttributeName value:url range:NSMakeRange(0, text.length)]; self.textView.attributedText = attributeStr; } 

效果图:

NSLinkAttributeName.png
点击链接后的页面.png

2.12 NSBaselineOffsetAttributeName —— 基础偏移量

注意:正值向上偏移,负值向下偏移,默认0(不偏移)

代码:

- (void)baselineOffsetAttributeName {NSString *text = @"正值向上偏移,无偏移效果,负值向下偏移!";NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; [attributeStr addAttribute:NSBaselineOffsetAttributeName value:@(10) range:NSMakeRange(0, 7)]; [attributeStr addAttribute:NSBaselineOffsetAttributeName value:@(-10) range:NSMakeRange(13, text.length - 13)]; self.label3.attributedText = attributeStr; } 

效果图:

NSBaselineOffsetAttributeName.png

2.13 NSObliquenessAttributeName —— 字体倾斜

注意:正值向右倾斜,负值向左倾斜, 默认0(不倾斜)

代码:

- (void)obliquenessTest {NSString *text = @"正值向右倾斜,无偏移效果,负值向左倾斜!";NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; [attributeStr addAttribute:NSObliquenessAttributeName value:@(1) range:NSMakeRange(0, 7)]; [attributeStr addAttribute:NSObliquenessAttributeName value:@(-1) range:NSMakeRange(13, text.length - 13)]; self.label.attributedText = attributeStr; } 

效果图:

NSObliquenessAttributeName.png

2.14 NSExpansionAttributeName —— 文本扁平化(横向拉伸)

注意:正值横向拉伸,负值横向压缩,默认0(不拉伸)

代码:

- (void)expansionAttributeTest {NSString *text = @"正值横向拉伸,无扁平效果,负值横向压缩!";NSMutableAttributedString * attributeStr = [[NSMutableAttributedString alloc] initWithString:text]; [attributeStr addAttribute:NSExpansionAttributeName value:@(0.8) range:NSMakeRange(0, 7)]; [attributeStr addAttribute:NSExpansionAttributeName value:@(-0.8) range:NSMakeRange(13, text.length - 13)]; self.label.attributedText = attributeStr; } 

效果图:

NSExpansionAttributeName.png

3. 图文混排

应用场景:如果界面需要显示一串从后台拿到的一个文本,这个文本有长有短,要求文本后面要拼接一个图片,而且如果文本长度为超过一行,图片要跟在文本的最后面。此时就要求图片似乎作为一个文本一样,可以拼接在后台拿到的文本后面。类似这样的:

应用场景举例:图片在文字前面
应用场景举例:图片在文字中间
应用场景举例:图片在文字后面

这样的效果还是通过NSAttributedString类实现的。步骤:

  1. 使用文本生成指定样式的AttributedString;
  2. 使用图片生成AttributedString;
  3. 将生成的AttributedString拼接起来。
  • 参考代码:
// 1. 由文本生成attributedString
+ (NSAttributedString *)attributedStringWithText:(NSString *)text textColor:(UIColor *)color textFont:(UIFont *)font hasUnderlineStyle:(BOOL)hasUnderLineStyle lineSpacing:(float)line paragraphSpacing:(float)paragraph { NSMutableAttributedString *attributedString = [[NSMutableAttributedString alloc] initWithString:text]; NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; NSRange range = NSMakeRange(0, text.length); [paragraphStyle setLineSpacing:line]; [paragraphStyle setParagraphSpacing:paragraph]; [attributedString addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:range]; [attributedString addAttribute:NSForegroundColorAttributeName value:color range:range]; [attributedString addAttribute:NSFontAttributeName value:font range:range]; if (hasUnderLineStyle) { [attributedString addAttribute:NSUnderlineStyleAttributeName value:[NSNumber numberWithInteger:NSUnderlineStyleSingle] range:range]; } return attributedString; } // 2. 由图片生成attributedString + (NSAttributedString *)attributedStringWithImage:(UIImage *)image imageBounds:(CGRect)bounds { NSTextAttachment *textAttachment = [[NSTextAttachment alloc] init]; textAttachment.image = image; textAttachment.bounds = CGRectMake(bounds.origin.x, bounds.origin.y, bounds.size.width, bounds.size.height); NSAttributedString *attachmentAttributedString = [NSAttributedString attributedStringWithAttachment:textAttachment]; return attachmentAttributedString; } // 3. 多个AttributedString拼接成一个resultAttributedString + (NSAttributedString *)jointAttributedStringWithItems:(NSArray *)items { NSMutableAttributedString *resultAttributedString = [[NSMutableAttributedString alloc] init]; for (int i = 0; i < items.count; i++) { if ([items[i] isKindOfClass:[NSAttributedString class]]) { [resultAttributedString appendAttributedString:items[i]]; } } return resultAttributedString; } 

图片在文字之后的调用方式:

- (void)initializeLabel:(UILabel *)label withText:(NSString *)text {// 传健文本的attributedStringNSAttributedString *textAttributedString = [UILabel attributedStringWithText:text textColor:[UIColor blackColor] textFont:[UIFont systemFontOfSize:20] hasUnderlineStyle:NO lineSpacing:6 paragraphSpacing:16]; // 创建图片的attributedString NSAttributedString *imageAttributedString = [UILabel attributedStringWithImage:[UIImage imageNamed:@"lovebook.png"] imageBounds:CGRectMake(0, -5, 109, 28)]; // 将文本和图片的attributedString拼接成一个resultAttributedString NSAttributedString *resultAttributedString = [UILabel jointAttributedStringWithItems:@[textAttributedString, imageAttributedString]]; // 将resultAttributedString赋值给label label.attributedText = resultAttributedString; } 

其他图片在文字前、在文字中的调用方式和上面的代码类似,这里不再赘述!

PS: 关于图文混排参考这篇文章, 写的很好,收获很大,感谢分享!

最后附一张属性表图:


image.png

转载于:https://www.cnblogs.com/shenlaiyaoshi/p/8555342.html

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/571105.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

运维工程师必会的linux命令下载,运维工程师必会的109个Linux命令.pdf

Linux公社运维工程师必会的109 个Linux 命令版本 1.0崔存新目录1 文件管理 51.1 basename 51.2 cat 51.3 cd 61.4 chgrp 61.5 chmod 71.6 chown 81.7 comm 91.8 cp91.9 cut 101.10 dd 111.11 diff 121.12 dir 131.13 dos2unix 151.14 egrep 161.15 fgrep 161.16 file 161.17 fi…

pdf.js 文字丢失问题 .cmaps

使用pdf.js 展示pdf文件 需求&#xff1a;电子发票类的pdf文件&#xff0c;以base64流的形式请求到&#xff0c;在浏览器中展示pdf文件 遇到的问题&#xff1a; 正常展示后&#xff0c;部分文字无法正常显示&#xff0c; 正常显示如下&#xff1a; 文件目录&#xff1a; js:fun…

linux红黑树节点没有数据,真正理解红黑树,真正的(Linux内核里大量用到的数据 -电脑资料...

作为一种数据结构&#xff0c;红黑树可谓不算朴素&#xff0c;因为各种宣传让它过于神秘&#xff0c;网上搜罗了一大堆的关于红黑树的文章&#xff0c;不外乎千篇一律&#xff0c;介绍概念&#xff0c;分析性能&#xff0c;贴上代码&#xff0c;然后给上罪恶的一句话&#xff0…

bzoj3631: [JLOI2014]松鼠的新家

容易发现是树剖裸题。 然后毒瘤选手AKC表示好像可以用树上差分LCA做。 就这样。水题。 诶那你咋没秒切。 妈也看错样例&#xff0c;然后画错图&#xff0c;接着就是理解错题目&#xff0c;最后R成傻逼之时发现我ST表开数组的顺序错了。。。 废物。 #include<cstdio> #inc…

超过4g的文件怎么上传到linux,怎么免费上传大于4G的文件到百度云 大于4G的文件不开会员怎么上传到百度云...

4G管家appv1.0 安卓版类型&#xff1a;系统工具大小&#xff1a;13.1M语言&#xff1a;中文 评分&#xff1a;10.0标签&#xff1a;立即下载百度云可以非常方便大家存储一些大文件资料&#xff0c;而且百度云的容量也非常高&#xff0c;不过如果你是普通用户的话要想上传大于4g…

scanf和printf在c语言中的作用,C语言中的scanf与printf

最初学习C语言程序设计时&#xff0c;经常需要通过键盘交互方式请用户输入内容&#xff0c;并需要将用户计算的结果在屏幕上输出。为实现这样的操作&#xff0c;C语言提供了scanf与printf两个函数&#xff0c;使用它们之前&#xff0c;一般需要包含stdio.h头文件。语法是&#…

linux sed 循环多行,linux sed 多行处理详细总结

在正常情况下&#xff0c;sed将待处理的行读入模式空间&#xff0c;脚本中的命令就一条接着一条的对该行进行处理&#xff0c;直到脚本执行完毕&#xff0c;然后该行被输出&#xff0c;模式空间请空&#xff1b;然后重复刚才的动作&#xff0c;文件中的新的一行被读入&#xff…

c语言第六次上机作业,C语言第五次上机作业参考答案

该楼层疑似违规已被系统折叠 隐藏此楼查看此楼#include#define N 3void average(int x[N][10]);void findgood(int x[N][10]);void findfail(int x[N][10]);void main(){//0:学号,1-5:成绩,6:平均分,7:第一门平均分,8:是否及格,9:是否优秀int stu[N][10]{0},i,j,s[N]{0};printf…

华农c语言实验1007答案,华农C语言题目及答案(完整版).docx

[题目6567&#xff1a;The first C Program]将下列程序输入visual c&#xff0c;编译、连接和运行该程序。#include"stdio.h"main(){printf("The first C Program\n");}答案#include #include int main(){printf("The first C Program\n");retur…

C语言中声明复数用什么字母,用c语言定义复数-20210407134457.docx-原创力文档

标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]标准化管理处编码[BBX968T-XBB8968-NNJ668-MM9N]用c语言定义复数实验0 预备实验实验题目&#xff1a;用c语言的结构类型定义表示复数(1)用浮点型(2)实行-*、/运算实验代码&#xff1a;#include<>typedef struct{int e1,e2;…

go语言 c# 混合编程 pdf,C# 结合 Golang 开发

1. 实现方式与语法形式基本方式&#xff1a;将 Go 程序编译成 DLL 供 C# 调用。1.1 Go代码注意&#xff1a;代码中 export 的注释是定义的入口描述不能省略package mainimport "C"import "fmt"func main() {fmt.Println(Test())}var _count 0//Test ://ex…

android 屏幕坐标色彩,Android自定义View实现颜色选取器

Android 自定义View 颜色选取器&#xff0c;可以实现水平、竖直选择颜色类似 SeekBar 的方式通过滑动选择颜色。效果图xml 属性1.indicatorColor 指示点颜色2.indicatorEnable 是否使用指示点3.orientation 方向horizontal 水平vertical 竖直使用复制 \library\src…\ColorPick…

android移除动画,android – 如何使用ObjectAnimator删除动画的慢端?

我有这个ObjectAnimator&#xff1a;cloudAnim2 ObjectAnimator.ofFloat(cloud2ImageView,"x",500,1000);cloudAnim2.setDuration(3000);cloudAnim2.setRepeatCount(ValueAnimator.INFINITE);cloudAnim2.setRepeatMode(ValueAnimator.RESTART);cloudAnim2.start();c…

linux右键菜单的截图,Linux: 给右键菜单加一个“转换图片为jpg格式”

Linux上通常都会安装imagemagick这个小巧但又异常强大的工具。这个软件提供了一系列很好用的功能。这里说一说如何使用它的convert命令转换图片为jpg格式&#xff0c;以及如何把它添加到Thunar的右键菜单。convert转换图片为jpg格式用起来超简单&#xff1a;convert -format jp…

eclipse实现Android登录功能,eclipse开发安卓登录

划线的地方怎么解决啊&#xff1f;有没有大佬知道如何修改package com.example.login;import android.app.Activity;import android.content.Context;import android.content.Intent;import android.content.SharedPreferences;import android.content.SharedPreferences.Edito…

android tcp 最优窗口,Android 面试必备 - 计算机网络基本知识(TCP,UDP,Http,https)...

简介HTTP协议(超文本传输协议)和 UDP(用户数据包协议)&#xff0c;TCP 协议(传输控制协议)TCP/IP是个协议组&#xff0c;可分为四个层次&#xff1a;网络接口层、网络层、传输层和应用层。在网络层有IP协议、ICMP协议、ARP协议、RARP协议和BOOTP协议。在传输层中有TCP协议与UDP…

c语言10个数如何求最大值,C语言,输入10个数怎样输出10个数中最大值,最小值(大一计算机)...

可以参考下面的代码&#xff1a;#include int main(){int loop 10;int min, max, value;do{printf("输入整数:");scanf("%d", &value);if (loop10) {max min value; loop--; continue;} else {if (value > max) max value;if (value loop--;}} …

android波纹效果弹窗,Android自定义View实现波纹效果

Android自定义View实现波纹效果时间&#xff1a;2017-05-27 来源&#xff1a;移动互联网学院1、引言&#xff1a;随着Android智能手机的普及&#xff0c;Android应用得到了大力支持&#xff0c;而Android应用的市场前景也是非常的强势。在Android应用的实际开发中&#xff…

Python 构建前端 页面继承及共享 - 转

http://blog.csdn.net/youzhouliu/article/details/52181549转载于:https://www.cnblogs.com/wag-tail-118/articles/8564522.html

android service onlowmemory,Android乱弹onLowMemory()和onTrimMemory()

今天看郭哥的LitePal框架的源码,刚打开LitePalApplication里面的源码看到了这样一幕Overridepublic void onLowMemory() {super.onLowMemory();mContext getApplicationContext();}不太懂郭哥的意思.之前依稀记得有人说起onLowMemory()和onTrimMemory(),于是乎,我就去查了查源…