2012-05-11 37 views
2

我正在做一個項目,如記筆記一樣處理當天的任務。
所以我分配每天的任務做,當任務完成時,我想要一行通過任務名稱罷工。
我正在尋找具有此透視線的相應字體系列,但失敗。
所以請爲我建議一個.ttf字體名稱,以便我可以在我的項目中使用該字體來滿足我的要求。字體通過它

NSString *string = Yourlabel.text; 
CGSize stringSize = [string sizeWithFont:Yourlabel.font]; 
CGRect buttonFrame = Yourlabel.frame; 
CGRect labelFrame = CGRectMake(buttonFrame.origin.x ,  
buttonFrame.origin.y + stringSize.height/2,  
                                          stringSize.width, 2); 
UILabel *lineLabel = [[UILabel alloc] initWithFrame:labelFrame]; 
lineLabel.backgroundColor = [UIColor blackColor]; 
[CellView addSubview:lineLabel]; 

回答

5

****** OPTION 1 ******

,如果你想通過多模式文本罷工:使用TTTAttributedLabel

創造新TTTAttributedLabel.h和TTTAttributedLabel.m文件(從GitHub沒有,因爲我用的單/雙刪除功能改動)

http://www.2shared.com/file/Z_qZpWVd/TTTAttributedLabel.html

http://www.2shared.com/file/xXjmC-1M/TTTAttributedLabel.html

,並在您需要的刪除標籤 - 使用TTTAttributedLabel而不是UILabel

要設置透溼 =

TTTAttributedLabel *labelName = [[TTTAttributedLabel alloc] init]; 

labelName.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] 
       forKey:@"TTTCustomStrikeOut"]; 

要設置doublethrough =

TTTAttributedLabel *labelName = [[TTTAttributedLabel alloc] init]; 

labelName.linkAttributes = [NSDictionary dictionaryWithObject:[NSNumber numberWithBool:YES] 
       forKey:@"TTTCustomDoubleStrikeOut"]; 

添加其中標籤文本應當刪除線出來+範圍提供可點擊的鏈接(零,因爲沒有鏈路) :

//set link to nil, to NOT-have a link on taping on this label. 
[labelName addLinkToURL:nil withRange:NSMakeRange(0, [labelName.text length])]; 

P.S. - 要正確地重新定位雙擊刪除行 - 請編輯TTTAtributedLabel.m文件,在第483,484和489,490行(當前我已將中間的上行y-2和下行y + 2更改爲了更好的結果。)

****** OPTION 2 ******

將所有字符串符號轉換爲特殊穿透字符。

你可以從這個網頁讓他們:http://adamvarga.com/strike/

那麼你可以 - 例如,把必要的符號翻譯語言文件:

「A」 =「A」; 「B」=「B̶」; 「C」=「C」; 「D」=「D」; 「E」=「E̶」; 「F」=「F」; 「G」=「G̶」; 「H」=「H」; ....

和使用該功能,以打開正常文本字符串刪除線出字符串:

- (NSString *)returnStrikedOutTextFromString:(NSString *)mString 
{ 
    NSString * mNewString = @""; 

    for(int i = 0; i<[mString length]; i++) 
    { 
     mNewString = [NSString stringWithFormat:@"%@%@",mNewString, 
     NSLocalizedString([[mString substringToIndex:i+1] substringFromIndex:i],nil)]; 
    } 

    return mNewString; 
} 

例如:

textLabel.text = [self returnStrikedOutTextFromString:@"string text"]; 

**** OPTION 3 *** *

我也建議嘗試這裏提到的這個UILabel子類:Underline text in UIlabel

希望有所幫助!

+0

嘿感謝的人.... :) – KDeogharkar

+0

嗨..只有一個問題..你知道是否有雙重打通工具可用或不。如果它是提前發送給我的鏈接.. thanx。 – KDeogharkar

+0

嗨kdeo_16 - 我調整了一點TTTAtributedLabel,現在它支持雙刪除。這是一個快速修復,它的工作原理。 (請參閱更新後的答案),但請繼續調整以獲得更好的結果:)希望有所幫助! :) –

2

使用下面的代碼通過線條紋代碼是

UILabel *canceledlable = [[UILabel alloc] initWithFrame:yourmainlableframe]; 
canceledlable.opaque = YES; 
canceledlable.backgroundColor = [UIColor clearColor]; 
canceledlable.text = @"------------------------------------------------"; 
canceledlable.lineBreakMode = UILineBreakModeClip; 
[self.view addSubview: canceledlable]; 

這裏它拉布勒希望你刪除線字體只是給它的框架在這​​裏,並添加此拉布勒當你的任務完成 希望,這HEL p你...... :)

2

如果使用其他簡單的想法,其做工精細,也很容易....

只需添加您拉布勒和拉布勒上方的另一圖標:

+1

謝謝。它的工作適合我而不使用第三方。 –

1

試試用TTTAttributedLabel添加這個功能。

@implementation TTTAttributedLabel (Additions) 

- (void)setStrikeThroughOn:(BOOL)isStrikeThrough { 
    NSString* text = self.text; 
    [self setText:text afterInheritingLabelAttributesAndConfiguringWithBlock:^  NSMutableAttributedString *(NSMutableAttributedString *mutableAttributedString) { 
    NSRange strikeRange = [[mutableAttributedString string] rangeOfString:text options:NSCaseInsensitiveSearch]; 
    [mutableAttributedString addAttribute:kTTTStrikeOutAttributeName value:[NSNumber numberWithBool:isStrikeThrough] range:strikeRange]; 
    return mutableAttributedString; 
}]; 

// must trigger redraw 
[self setNeedsDisplay]; 
} 

@end 
0

在斯威夫特,

let label = UITextView(frame: CGRectMake(0, 0, 300, 100)) 
let strikeThroughAttributes = [NSStrikethroughStyleAttributeName: NSUnderlineStyle.StyleSingle.rawValue] 
let labelString = NSAttributedString(string: "Hello, playground", attributes: strikeThroughAttributes) 
label.attributedText = labelString