macOS/iOS API解説

iOS , Mac アプリケーション開発のために使われる主要フレームワークの日本語情報です。2010年代に書かれた内容です。今後更新はありません。

目次

fixAttachmentAttributeInRange:

指定した範囲のアタッチメントを取り除きます
-(void)fixAttachmentAttributeInRange:(NSRange)aRange:

解説

指定した範囲のアタッチメントを取り除きます。指定した範囲(aRange)がレシーバを越えれば

返り値

( void )

なし

引数

( NSRange )aRange

範囲

フレームワーク

ApplicationKit

クラス

NSMutableAttributedString Additions

Instance Methods

使用可能

10.0

参照

- fixFontAttributeInRange:
- fixParagraphStyleAttributeInRange:
- fixAttributesInRange:

例文

#import "MyObject.h"
//TextViewからこのクラスにdelegateしている
@implementation MyObject
- (void)textView:(NSTextView *)aTextView clickedOnCell:(id <NSTextAttachmentCell>)attachmentCell inRect:(NSRect)cellFrame

{
NSLog([NSString stringWithFormat:@"%.1f,%.1f,%.1f,%.1f",cellFrame.origin.x,cellFrame.origin.y,cellFrame.size.width,cellFrame.size.height]);
}

- (IBAction)myAction:(id)sender
{
    //範囲
    NSRange ran;
    //テキストアタッチメント
    NSTextAttachment *theAttachment;
    //ファイルラッパ
    NSFileWrapper *theWrapper = [[[NSFileWrapper alloc] initWithPath:
            [[NSBundle mainBundle] pathForResource:@"image" ofType:@"tiff"]] autorelease];
            
    //変更可能な属性付き文字列
    NSMutableAttributedString *maStr =[[NSMutableAttributedString alloc]
                    initWithString:@"" attributes:nil];
                    
    NSMutableAttributedString *maStr2 =[[[NSMutableAttributedString alloc] initWithString:@"theString" attributes:nil] autorelease];
        
    //テキストアタッチメント
    theAttachment = [[[NSTextAttachment alloc] initWithFileWrapper:theWrapper] autorelease];
    
    
    //変更可能な属性付き文字列にアタッチメント
    maStr = [NSMutableAttributedString attributedStringWithAttachment:theAttachment];

    [maStr setAttributedString:maStr2];
    //やっぱり削除
    [maStr fixAttachmentAttributeInRange:NSMakeRange(0,1)];
    //テキストビューに追加
    [[myOutlet textStorage] appendAttributedString:maStr];
            
    ran = NSMakeRange(1,3);
    [myOutlet insertText:@"<-clich!"];
    
    [myOutlet smartInsertBeforeStringForString:@"sss"
            replacingRange:ran];
            

    
    
            
}

@end