問題があります。第三者libのframe.size.widthを変更できません。幅を変更するための通常の解決策が見つかりませんでしたので、私はobjc/runtimeを実行することにしました。Objective-C初期化されたオブジェクトの実行時に変更されるreadonlyプロパティ
私はViewControllerとそのプロパティを持っていますDTAttributedTextView * v。
@interface DTAttributedTextView : UIScrollView
{
// ivars needed by subclasses
DTAttributedTextContentView *_attributedTextContentView;
}
@property (nonatomic, strong) NSAttributedString *attributedString;
@property (nonatomic, DT_WEAK_PROPERTY) IBOutlet
id<DTAttributedTextContentViewDelegate> textDelegate;
@property (nonatomic, strong) IBOutlet UIView *backgroundView;
....
@end
vが@property(..、読み取り専用)DTAttributedTextContentView * attributedTextContentView
@interface DTAttributedTextContentView : UIView
{
NSAttributedString *_attributedString;
DTCoreTextLayoutFrame *_layoutFrame;
UIEdgeInsets _edgeInsets;
NSMutableDictionary *customViewsForAttachmentsIndex;
BOOL _flexibleHeight;
// for layoutFrame
NSInteger _numberOfLines;
NSLineBreakMode _lineBreakMode;
NSAttributedString *_truncationString;
}
attributedTextContentViewだから基本的に私がする必要がある@property DTCoreTextLayoutFrame * layoutFrame
@interface DTCoreTextLayoutFrame : NSObject
{
CGRect _frame;
NSArray *_lines;
NSArray *_paragraphRanges;
NSArray *_textAttachments;
NSAttributedString *_attributedStringFragment;
}
を得ました変更
私は、ドット表記法によるアイバーズにアクセスし、また&場合CGFloat必要なイベントとしてCGStructを送信することはできませんので、私はobjc_setAssociatedObject(self.v.attributedTextContentView.layoutFrame,@"frame.size.width",@200,OBJC_ASSOCIATION_ASSIGN);
も
objc_setAssociatedObject(self.v.attributedTextContentView.layoutFrame,@"frame",CGRectMake(0,0,200,1000),OBJC_ASSOCIATION_ASSIGN);
を使用するカントピティーため
self.v.attributedTextContentView.layoutFrame.frame.size.width
。
この状況の別の解決策として、私は実行時にオブジェクトを使ってオブジェクトを作成してからポインタを変更する方法を見ています。コピーを使用していくつかのステップを実行できます。 私の問題は、objc/runtimeのim new tieですし、ドキュメントも実際には貧弱です。 Imはこの重要な技術を学ぶのに苦労しているので、私は意図的に他のオプションを使って正確な問題を解決していません。
ご協力いただければ幸いです。 Thanxは事前に
私はスタンドアートオブジェクトの作成を使用してフレームで元の問題を解決しました。しかし、動的な値の変更のためにランタイムを使用することは、現実のままです。 – KysokZla