iOS 富文本風格NSMutableParagraphStyle、定制UITextView插入圖片和定制復制

問題一
開發過程中,經常會遇到動態計算行高的問題,?

- (CGRect)boundingRectWithSize:(CGSize)size options:(NSStringDrawingOptions)options attributes:(nullableNSDictionary<NSString?*,?id> *)attributes context:(nullable?NSStringDrawingContext?*)contextNS_AVAILABLE(10_11,?7_0);

是蘋果推薦的計算方法,顯然會遇到段落格式問題,例如行間距、縮進等格式設置需求,attributes傳進來的字典中,包含我們設置的字體及格式,其中NSParagraphStyleAttributeName是設置段落風格,NSFontAttributeName是設置字體。

ok,具體來看一下NSParagraphStyleAttributeName的功能。

[objc]?view plaincopy
print?在CODE上查看代碼片派生到我的代碼片
  1. //???NSParagraphStyleAttributeName?段落的風格(設置首行,行間距,對齊方式什么的)看自己需要什么屬性,寫什么????
  2. ????NSMutableParagraphStyle?*paragraphStyle?=?[[NSMutableParagraphStyle?alloc]?init];????
  3. ????paragraphStyle.lineSpacing?=?10;//?字體的行間距????
  4. ????paragraphStyle.firstLineHeadIndent?=?20.0f;//首行縮進????
  5. ????paragraphStyle.alignment?=?NSTextAlignmentJustified;//(兩端對齊的)文本對齊方式:(左,中,右,兩端對齊,自然)????
  6. ????paragraphStyle.lineBreakMode?=?NSLineBreakByTruncatingTail;//結尾部分的內容以……方式省略?(?"...wxyz"?,"abcd..."?,"ab...yz")????
  7. ????paragraphStyle.headIndent?=?20;//整體縮進(首行除外)????
  8. ????paragraphStyle.tailIndent?=?20;//????
  9. ????paragraphStyle.minimumLineHeight?=?10;//最低行高????
  10. ????paragraphStyle.maximumLineHeight?=?20;//最大行高????
  11. ????paragraphStyle.paragraphSpacing?=?15;//段與段之間的間距????
  12. ????paragraphStyle.paragraphSpacingBefore?=?22.0f;//段首行空白空間/*?Distance?between?the?bottom?of?the?previous?paragraph?(or?the?end?of?its?paragraphSpacing,?if?any)?and?the?top?of?this?paragraph.?*/????
  13. ????paragraphStyle.baseWritingDirection?=?NSWritingDirectionLeftToRight;//從左到右的書寫方向(一共??三種)????
  14. ????paragraphStyle.lineHeightMultiple?=?15;/*?Natural?line?height?is?multiplied?by?this?factor?(if?positive)?before?being?constrained?by?minimum?and?maximum?line?height.?*/????
  15. ????paragraphStyle.hyphenationFactor?=?1;//連字屬性?在iOS,唯一支持的值分別為0和1????

好了,現在就可以很輕松的計算某一段落高度,例如:

[objc]?view plaincopy
print?在CODE上查看代碼片派生到我的代碼片
  1. _descAtt?=?[[NSMutableAttributedString?alloc]?initWithString:_model.desc];??
  2. ???????UIFont?*descFont?=?[UIFont?PingFangSC_Regular_WithSize:12];??
  3. ?????????
  4. ???????NSMutableParagraphStyle?*descStyle?=?[[NSMutableParagraphStyle?alloc]init];??
  5. ???????[descStyle?setLineSpacing:1];//行間距??
  6. ?????????
  7. ???????CGSize?descSize?=?[_model.desc?boundingRectWithSize:CGSizeMake(w,?MAXFLOAT)??
  8. ???????????????????????????????????????????????????options:NSStringDrawingUsesLineFragmentOrigin??
  9. ????????????????????????????????????????????????attributes:@{NSFontAttributeName:descFont,??
  10. ?????????????????????????????????????????????????????????????NSParagraphStyleAttributeName?:descStyle}??
  11. ???????????????????????????????????????????????????context:nil].size;??

另外,再介紹幾個富文本處理的屬性:

[objc]?view plaincopy
print?在CODE上查看代碼片派生到我的代碼片
  1. //?NSFontAttributeName????????????????設置字體屬性,默認值:字體:Helvetica(Neue)?字號:12??
  2. //?NSForegroundColorAttributeNam??????設置字體顏色,取值為?UIColor對象,默認值為黑色??
  3. //?NSBackgroundColorAttributeName?????設置字體所在區域背景顏色,取值為?UIColor對象,默認值為nil,?透明色??
  4. //?NSLigatureAttributeName????????????設置連體屬性,取值為NSNumber?對象(整數),0?表示沒有連體字符,1?表示使用默認的連體字符??
  5. //?NSKernAttributeName????????????????設定字符間距,取值為?NSNumber?對象(整數),正值間距加寬,負值間距變窄??
  6. //?NSStrikethroughStyleAttributeName??設置刪除線,取值為?NSNumber?對象(整數)??
  7. //?NSStrikethroughColorAttributeName??設置刪除線顏色,取值為?UIColor?對象,默認值為黑色??
  8. //?NSUnderlineStyleAttributeName??????設置下劃線,取值為?NSNumber?對象(整數),枚舉常量?NSUnderlineStyle中的值,與刪除線類似??
  9. //?NSUnderlineColorAttributeName??????設置下劃線顏色,取值為?UIColor?對象,默認值為黑色??
  10. //?NSStrokeWidthAttributeName?????????設置筆畫寬度,取值為?NSNumber?對象(整數),負值填充效果,正值中空效果??
  11. //?NSStrokeColorAttributeName?????????填充部分顏色,不是字體顏色,取值為?UIColor?對象??
  12. //?NSShadowAttributeName??????????????設置陰影屬性,取值為?NSShadow?對象??
  13. //?NSTextEffectAttributeName??????????設置文本特殊效果,取值為?NSString?對象,目前只有圖版印刷效果可用:??
  14. //?NSBaselineOffsetAttributeName??????設置基線偏移值,取值為?NSNumber?(float),正值上偏,負值下偏??
  15. //?NSObliquenessAttributeName?????????設置字形傾斜度,取值為?NSNumber?(float),正值右傾,負值左傾??
  16. //?NSExpansionAttributeName???????????設置文本橫向拉伸屬性,取值為?NSNumber?(float),正值橫向拉伸文本,負值橫向壓縮文本??
  17. //?NSWritingDirectionAttributeName????設置文字書寫方向,從左向右書寫或者從右向左書寫??
  18. //?NSVerticalGlyphFormAttributeName???設置文字排版方向,取值為?NSNumber?對象(整數),0?表示橫排文本,1?表示豎排文本??
  19. //?NSLinkAttributeName????????????????設置鏈接屬性,點擊后調用瀏覽器打開指定URL地址??
  20. //?NSAttachmentAttributeName??????????設置文本附件,取值為NSTextAttachment對象,常用于文字圖片混排??
  21. //?NSParagraphStyleAttributeName??????設置文本段落排版格式,取值為?NSParagraphStyle?對象??

——————————————————————————————————————————————————————————————————

問題二

一、設置textView的行間距
1.如果只是靜態顯示textView的內容為設置的行間距,執行如下代碼:

//    textview 改變字體的行間距 NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init]; paragraphStyle.lineSpacing = 10;// 字體的行間距 NSDictionary *attributes = @{ NSFontAttributeName:[UIFont systemFontOfSize:15], NSParagraphStyleAttributeName:paragraphStyle }; textView.attributedText = [[NSAttributedString alloc] initWithString:@"輸入你的內容" attributes:attributes];2.如果是想在輸入內容的時候就按照設置的行間距進行動態改變,那就需要將上面代碼放到textView的delegate方法里-(void)textViewDidChange:(UITextView *)textView{//    textview 改變字體的行間距NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];paragraphStyle.lineSpacing = 20;// 字體的行間距NSDictionary *attributes = @{NSFontAttributeName:[UIFont systemFontOfSize:15],NSParagraphStyleAttributeName:paragraphStyle};textView.attributedText = [[NSAttributedString alloc] initWithString:textView.text attributes:attributes];}一、設置textView的placeholderUITextView上如何加上類似于UITextField的placeholder呢,其實在UITextView上加上一個UILabel或者UITextView,如果用UILable的話,會出現一個問題就是當placeholder的文字過長導致換行的時候就會出現問題,而用UITextView則可以有效避免此問題。- (BOOL)textView:(UITextView *)textView shouldChangeTextInRange:(NSRange)range replacementText:(NSString *)text{    if (![text isEqualToString:@""]){_placeholderLabel.hidden = YES;}if ([text isEqualToString:@""] && range.location == 0 && range.length == 1){_placeholderLabel.hidden = NO;}return YES;}說明如下:(1) _placeholderLabel 是加在UITextView后面的UITextView,_placeholderLabel要保證和真正的輸入框的設置一樣,字體設置成淺灰色,然后[_placeholderLabel setEditable:NO];真正的輸入框要設置背景色透明,保證能看到底部的_placeholderLabel。(2) [text isEqualToString:@""] 表示輸入的是退格鍵(3) range.location == 0 && range.length == 1 表示輸入的是第一個字符
————————————————————————————————————————————————————————————————————

問題三

?

UITextView富文本、插入圖片

直接看代碼 ?

_textView ?是定義的成員變量

[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. _textView?=?[[UITextView?alloc]init];??
  2. ???_textView.font?=?[UIFont?systemFontOfSize:13];??
  3. ???_textView.backgroundColor?=?[UIColor?lightGrayColor];??
  4. ???_textView.text?=?[NSString?stringWithFormat:@"settttttttttt?:%@",self.countStr];??
  5. ???_textView.frame?=?CGRectMake(20,?100,?200,?130);??
  6. ???_textView.delegate?=?self;??
  7. ???[self.view?addSubview:_textView];??

通過代理方法 ?得到選中文字的起始位置和長度 ?通過定義成員變量的方式保存起來 ?代碼如下

[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. -?(void)textViewDidChangeSelection:(UITextView?*)textView?{??
  2. ??????
  3. ????/**?
  4. ?????*?可以通過得到復制的長度進行判斷是否有進行復制操作??再通過位置、長度進行字體變化?
  5. ?????*/??
  6. ????_loc?=?(int)textView.selectedRange.location;??
  7. ????_len?=?(int)textView.selectedRange.length;??
  8. ??????
  9. }??

富文本 ? 讓選中的字體加粗或者改變顏色都可以 ?代碼中是點擊按鈕觸發字體選中改變方法

[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. -?(void)btnClick{??
  2. ??????
  3. ????if?(_len)?{????
  4. ??????????
  5. ????????//怎么讓選中的字體加粗呢??
  6. ????????NSMutableAttributedString?*AttributedStr?=?[[NSMutableAttributedString?alloc]initWithString:_textView.text];??
  7. ????????[AttributedStr?addAttribute:NSFontAttributeName??
  8. ???????????
  9. ??????????????????????????????value:[UIFont?boldSystemFontOfSize:15.0]??
  10. ???????????
  11. ??????????????????????????????range:NSMakeRange(_loc,?_len)];??
  12. ??????????
  13. ????????_textView.attributedText?=?AttributedStr;??
  14. ??????????
  15. ??????????
  16. ??????????
  17. ????}??
  18. ??????
  19. }??

圖片插入 ?代碼中也是通過按鈕觸發方法 ?點擊按鈕 復制一張圖片到光標位置

[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. -?(void)copyBtnClick{??
  2. ??????
  3. ????NSMutableAttributedString?*string?=?[[NSMutableAttributedString?alloc]?initWithAttributedString:_textView.attributedText];??
  4. ??????
  5. ????NSTextAttachment?*textAttachment?=?[[NSTextAttachment?alloc]?initWithData:nil?ofType:nil]?;??
  6. ????textAttachment.image?=?[UIImage?imageNamed:@"111"];?//要添加的圖片??
  7. ??????
  8. ????NSAttributedString?*textAttachmentString?=?[NSAttributedString?attributedStringWithAttachment:textAttachment]?;??
  9. ??????
  10. ????[string?insertAttributedString:textAttachmentString?atIndex:_textView.selectedRange.location];//index為用戶指定要插入圖片的位置??
  11. ????_textView.attributedText?=?string;??
  12. ??
  13. }??

————————————————————————————————————————

問題四

繼承UITextView

1.定制選中文字的菜單

首先新建一個類,繼承自UITextView,假設類名為MyTextView,關鍵代碼如下:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. /*?選中文字后是否能夠呼出菜單?*/??
  2. -?(BOOL)canBecameFirstResponder?{??
  3. ????return?YES;??
  4. }??
  5. ??
  6. /*?選中文字后的菜單響應的選項?*/??
  7. -?(BOOL)canPerformAction:(SEL)action?withSender:(id)sender?{??
  8. ????if?(action?==?@selector(copy:))?{?//?菜單不能響應copy項??
  9. ????????return?NO;??
  10. ????}??
  11. ????else?if?(action?==?@selector(selectAll:))?{?//?菜單不能響應select?all項??
  12. ????????return?NO;??
  13. ????}??
  14. ??????
  15. ????//?事實上一個return?NO就可以將系統的所有菜單項全部關閉了??
  16. ????return?NO;??
  17. }??

以上第一個方法用來確保我們選中文字后的菜單可以彈出,第二個方法用來關閉菜單中所有系統的菜單項,如copy, select, select all等。

然后使用UIMenuController定制菜單:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. //?自定義text?view選中文字后的菜單??
  2. UIMenuItem?*selectItem?=?[[UIMenuItem?alloc]?initWithTitle:@"選擇文字"?action:@selector(callSelectText:)];??
  3. UIMenuItem?*cancelItem?=?[[UIMenuItem?alloc]?initWithTitle:@"取消選中"?action:@selector(cancelSelection:)];??
  4. [UIMenuController?sharedMenuController].menuItems?=?@[selectItem,?cancelItem];??

注意必須實現兩個MenuItem的響應方法才能顯示出菜單:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. #pragma?mark?-?Menu?Item?Actions??
  2. ??
  3. -?(void)callSelectText:(id)sender?{??
  4. ????self.currentSelection_?=?self.myTextView.selectedRange;??
  5. ????self.selectOptionView.hidden?=?NO;??
  6. ????[self.location_inputTextField?becomeFirstResponder];??
  7. }??
  8. ??
  9. -?(void)cancelSelection:(id)sender?{??
  10. ????self.myTextView.selectedRange?=?NSRangeZero;??
  11. }??



最終效果如下:


之前的項目沒有要求定制菜單項的圖像,直接看SDK的內容的話貌似也沒有Image之類的屬性或方法,所以深層次定制菜單項的內容不得而知了。


2.通過代碼選中一段文字

這個很簡單,直接改變UITextView的selectedRange屬性的值就可以了:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. @property(nonatomic)?NSRange?selectedRange;??

例如我們點擊選擇文字后彈出一個文字選擇的輸入視圖,這個我用一個XIB文件定制:


小心了,將xib中的UI組件和View Controller中的Outlet連接時,在代碼中要先從xib文件中加載視圖,才能使用其中的UI組件,例如:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. NSArray?*nibViews?=?[[NSBundle?mainBundle]?loadNibNamed:@"SelectOptionView"?owner:self?options:nil];??
  2. self.selectOptionView?=?nibViews[0];??
  3. self.selectOptionView.center?=?CGPointMake(self.view.center.x,?self.view.bounds.size.height?/?3);??
  4. self.selectOptionView.hidden?=?YES;??
  5. [self.view?addSubview:self.selectOptionView];??
  6. ??
  7. //?要先加載了nib,IBOutlet才有意義,然后再設置其屬性??
  8. self.location_inputTextField.delegate?=?self;??
  9. self.length_inputTextField.delegate???=?self;??

如果將

? ??self.location_inputTextField.delegate?=self;

? ??self.length_inputTextField.delegate?? =self;

這兩行代碼置于loadNibNamed方法之前,那么兩個文本輸入框的delegate將為空(因為他們本身都是空,還沒有加載)。

選擇文字的Action代碼為:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. #pragma?mark?-?Select?View?Actions??
  2. ??
  3. -?(IBAction)selectText:(id)sender?{??
  4. ????NSInteger?loc?=?self.location_inputTextField.text.integerValue;??
  5. ????NSInteger?len?=?self.length_inputTextField.text.integerValue;??
  6. ????NSUInteger?textLength?=?self.myTextView.text.length;??
  7. ????if?(loc?<?0?||?len?<?0?||?loc?>?textLength?||?len?>?textLength)?{??
  8. ????????UIAlertView?*alerView?=?[[UIAlertView?alloc]?initWithTitle:@"錯誤"??
  9. ???????????????????????????????????????????????????????????message:@"輸入出錯,輸入的數不能小于0和大于文本長度"??
  10. ??????????????????????????????????????????????????????????delegate:nil??
  11. ?????????????????????????????????????????????????cancelButtonTitle:@"確定"?otherButtonTitles:nil,?nil?nil];??
  12. ????????[alerView?show];??
  13. ????????return;??
  14. ????}??
  15. ????self.currentSelection_?=?NSMakeRange(loc,?len);??
  16. ????[self?finishSelectingText];??
  17. }??
  18. ??
  19. -?(IBAction)cancelSelectText:(id)sender?{??
  20. ????[self?finishSelectingText];??
  21. }??
  22. ??
  23. -?(void)finishSelectingText?{??
  24. ????[self.location_inputTextField?resignFirstResponder];??
  25. ????[self.length_inputTextField?resignFirstResponder];??
  26. ????self.selectOptionView.hidden?=?YES;??
  27. ??????
  28. ????[self.myTextView?becomeFirstResponder];??
  29. ????self.myTextView.selectedRange?=?self.currentSelection_;??
  30. }??

沒錯,只要一句self.myTextView.selectedRange?=self.currentSelection_;就可以了。

另外,我們可以在UITextView的以下方法中監聽到某段文字被選中:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. #pragma?mark?-?UITextView?Delegate??
  2. ??
  3. -?(void)textViewDidChangeSelection:(UITextView?*)textView?{??
  4. ????NSLog(@"Selection?changed");??
  5. ??????
  6. ????NSLog(@"loc?=?%d",?self.myTextView.selectedRange.location);??
  7. ????NSLog(@"len?=?%d",?self.myTextView.selectedRange.length);??
  8. }??

運行結果:



控制臺輸出如下:
[plain]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. 2014-02-16?23:33:56.197?MyTextView[4890:70b]?Selection?changed??
  2. 2014-02-16?23:33:56.198?MyTextView[4890:70b]?loc?=?507??
  3. 2014-02-16?23:33:56.198?MyTextView[4890:70b]?len?=?0??
  4. 2014-02-16?23:33:56.334?MyTextView[4890:70b]?Selection?changed??
  5. 2014-02-16?23:33:56.335?MyTextView[4890:70b]?loc?=?507??
  6. 2014-02-16?23:33:56.335?MyTextView[4890:70b]?len?=?5??
  7. 2014-02-16?23:34:05.291?MyTextView[4890:70b]?Selection?changed??
  8. 2014-02-16?23:34:05.292?MyTextView[4890:70b]?loc?=?10??
  9. 2014-02-16?23:34:05.292?MyTextView[4890:70b]?len?=?100??


3.讓鍵盤主動出現

為了讓用戶更省心,我們可以在一個帶輸入框的視圖出現時就讓鍵盤彈出來,而不用用戶再點一下輸入框了。方法很簡單,就一行代碼:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. [self.location_inputTextField?becomeFirstResponder];??


4.兩個輸入框按return時仿回車功能

有多個輸入框,在一個輸入框中按了return,然后好像在網站輸入框中按了回車,直接跳到下一個輸入框,這個也非常簡單,就是resignFirstResponder和becomeFirstResponder方法結合使用而已,在UITextField的委托方法中實現:
[objc]?view plaincopy
在CODE上查看代碼片派生到我的代碼片
  1. #pragma?mark?-?UITextField?Delegate??
  2. ??
  3. -?(BOOL)textFieldShouldReturn:(UITextField?*)textField?{??
  4. ????if?([self.location_inputTextField?isFirstResponder])?{??
  5. ????????[self.location_inputTextField?resignFirstResponder];??
  6. ????????[self.length_inputTextField?becomeFirstResponder];??
  7. ????}??
  8. ????else?if?([self.length_inputTextField?isFirstResponder])?{??
  9. ????????[self.length_inputTextField?resignFirstResponder];??
  10. ????}??
  11. ????return?YES;??
  12. }??



Demo已經上傳,有興趣的可以下載看看:點此進入下載頁


本文來自互聯網用戶投稿,該文觀點僅代表作者本人,不代表本站立場。本站僅提供信息存儲空間服務,不擁有所有權,不承擔相關法律責任。
如若轉載,請注明出處:http://www.pswp.cn/news/247923.shtml
繁體地址,請注明出處:http://hk.pswp.cn/news/247923.shtml
英文地址,請注明出處:http://en.pswp.cn/news/247923.shtml

如若內容造成侵權/違法違規/事實不符,請聯系多彩編程網進行投訴反饋email:809451989@qq.com,一經查實,立即刪除!

相關文章

day24 01 初識繼承

day24 01 初識繼承 面向對象的三大特性&#xff1a;繼承&#xff0c;多態&#xff0c;封裝 一、繼承的概念 繼承&#xff1a;是一種創建新類的方式&#xff0c;新建的類可以繼承一個或者多個父類&#xff0c;父類又可稱基類或超類&#xff0c;新建的類稱為派生類或者子類 class…

React基礎學習(第二天)

虛擬DOM JSX 涉及到 虛擬DOM ,簡單聊一下 定時器渲染問題 // 方法 function render() {//2. 創建react對象let el (<div><h3>時間更新</h3><p>{ new Date().toLocaleTimeString()}</p></div>)//3. 渲染ReactDOM.render(el, document.g…

iOS 去除字符串中的空格或多余空格(適合英文單詞)

NSString -stringByTrimmingCharactersInSet: 是個你需要牢牢記住的方法。它經常會傳入 NSCharacterSet whitespaceCharacterSet 或 whitespaceAndNewlineCharacterSet 來刪除輸入字符串的頭尾的空白符號。 需要重點注意的是&#xff0c;這個方法 僅僅 去除了 開頭 和 結尾 的…

華為交換機在Telnet登錄下自動顯示接口信息

因為用console連接交換機&#xff0c;默認是自動顯示接口信息的&#xff0c;比如down掉一個接口后&#xff0c;會自動彈出接口被down掉的信息&#xff0c;但是在telnet連接下&#xff0c;默認是不顯示這些信息的&#xff0c;需要開啟后才可顯示。 1、首先開啟info-center(默認是…

React基礎學習(第三天)

條件渲染 1. if / else render () {if (this.state.isLoading) { // 正在加載中return <h1>Loading...</h1>}return <div>這就是我們想要的內容</div>} // 鉤子函數 五秒鐘之后 修改狀態值componentDidMount () { setTimeout(() > {this.setState(…

componentsJoinedByString 和 componentsSeparatedByString 的方法的區別

將string字符串轉換為array數組 NSArray *array [Str componentsSeparatedByString:","]; &#xff1d;&#xff1d;反向方法 將array數組轉換為string字符串 NSString *tempString [mutableArray componentsJoinedByString:","];--,是分隔符 可不加分隔…

java中的各種數據類型在內存中存儲的方式

轉載別人的附上鏈接&#xff1a;https://blog.csdn.net/zj15527620802/article/details/80622314 1.java是如何管理內存的 java的內存管理就是對象的分配和釋放問題。&#xff08;其中包括兩部分&#xff09; 分配&#xff1a;內存的分配是由程序完成的&#xff0c;程序員需要通…

vscode的 jsonp 配置文件

{ // 工具-字體大小 “editor.fontSize”: 15, // 工具-tab縮進 “editor.tabSize”: 2, // 工具-在視區寬度換行 “editor.wordWrap”: “on”, // 工具-縮放 “window.zoomLevel”: 1, // 工具-編寫tab識別語言格式 “emmet.includeLanguages”: { “vue-html”: “html”, “…

NSString拼接字符串和NSPredicate詳解

NSString* string; // 結果字符串 02 NSString* string1, string2; //已存在的字符串&#xff0c;需要將string1和string2連接起來 03 04 //方法1. 05 string [[NSString alloc]initWithFormat:"%,%", string1, string2 ]; 06 07 //方法2. 08 string [string1 …

線程模塊

信號量 from threading import Semaphore,Thread import timedef func(a,b):time.sleep(1)sem.acquire()print(ab)sem.release()sem Semaphore(4) for i in range(10):t Thread(targetfunc,args(i,i5))t.start() 信號量事件 # 事件被創建的時候&#xff0c;默認為False狀態 #…

React中級學習(第一天)

Props深入 children 作用 : 獲取組件標簽的 子節點獲取方式 : this.props.children <App>此處的內容&#xff0c;就是組件的 children&#xff0c;將來通過組件的 props.children 就可以獲取到這些子節點了 </App>props 校驗 作用&#xff1a;規定組件props的類…

iOS 正則表達式判斷純數字以及匹配11位手機號碼

1用正則表達式 //是否是純數字(BOOL)isNumText:(NSString *)str{NSString * regex "(/^[0-9]*$/)";NSPredicate * pred [NSPredicate predicateWithFormat:"SELF MATCHES %", regex];BOOL isMatch [pred evaluateWithObject:st…

Elasticsearch集成ik分詞器

1、插件地址https://github.com/medcl/elasticsearch-analysis-ik/releases/download/v7.0.0/elasticsearch-analysis-ik-7.0.0.zip 2、找到對應版本的插件通過 http://192.168.1.8:9200查看ES的版本&#xff0c;找到對應的IK分詞插件 下載與之對應的版本https://github.com/me…

React中級學習(第二天)

JSX 語法的轉化過程 (了解) 演示 : babel中文網試一試 let h1 JSX 僅僅是createElement() 方法的語法糖 (簡化語法)JSX 語法 被 babel/preset-react 插件編譯為 createElement() 方法React 元素&#xff1a;是一個對象&#xff0c;用來描述你希望在屏幕上看到的內容React 元素…

【】MTCNN基于NCNN的測試過程

前言 操作過程 NCNN: https://github.com/Tencent/ncnn/wiki/how-to-build#build-for-linux-x86; vector初始化&#xff1a;int num[4] { 1, 4, 3, 2 }; int numLength sizeof(num) / sizeof(num[0]); vector<int> nums(num, num numLength); //使用數組初始化向量 Q&…

iOS NSTextAttachment - 圖文混排

蘋果在iOS7中推出了一個新的類NSTextAttachment&#xff0c;它是做圖文混排的利器&#xff0c;本文就是用這個類&#xff0c;只用50行代碼實現文字與表情混排&#xff0c;當然也可以實現段落中的圖文混排。 首先說一下文字和表情的混排&#xff1a; 先來做點兒準備工作&#…

vuex的結構有哪些參數?

查看參考地址&#xff1a; https://vuex.vuejs.org/zh/ vuex 狀態管理模式&#xff0c;相當于數據的中間商 注意&#xff1a; 為相同 屬性有&#xff1a; 1.State vue中的data —> 存放數據 2.Getter vue中的計算屬性computed —>將已有的數據進行計算再次利用 3.…

百煉OJ - 1004 - 財務管理

題目鏈接&#xff1a;http://bailian.openjudge.cn/practice/1004/ 思路 求和取平均。。。 #include <stdio.h>int main() {float sum0,a;for(int i0;i<12;i){scanf("%f",&a);sum a;}printf("$%.2f\n",sum/12);return 0; } 轉載于:https://w…

iOS 自定義Cell按鈕的點擊代理事件

在實際開發工作中&#xff0c;我們經常會在自定義的Cell中布局一些按鈕&#xff0c;并且很多時候我們會在點擊這個按鈕的時候使我們的UItableviewController跳轉到下一界面&#xff0c;有的可能還要傳值。那么如何使我們的控制器能夠獲知我們按下了cell的按鈕呢&#xff1f;毫無…

Google 開源技術protobuf 簡介與樣例

今天來介紹一下“Protocol Buffers ”&#xff08;以下簡稱protobuf&#xff09;這個玩意兒。本來俺在構思“生產者/消費者模式 ”系列的下一個帖子&#xff1a;關于生產者和消費者之間的數據傳輸格式。由于里面扯到了protobuf&#xff0c;想想干脆單獨開一個帖子算了。 ★prot…