来自C#的Hello World世界到Twitter(Hello World to Twitter from C#)
几天前,我发布了这个问题和这个问题,询问如何发布“Hello World”给twitter。 我得到了有益的回应,这促使我进一步前进,但我仍然迷失。
我需要使用OAuth,因为(因为我读它)使用用户名和密码将很快被弃用。
我需要一个例子,就像使用字符串常量'Hello World!'更新状态一样简单。
我的客户指定我必须使用C#。
A few days ago, I posted this question and this question asking about how to post "Hello World" to twitter. I've gotten helpful responses, which have propelled me further along, but I'm still lost.
I need to use OAuth because (as I read it) using username and password is going to be deprecated soon.
I need an example as simple as updating the status with the string constant 'Hello World!'.
My client is specifying that I must use C#.
原文:https://stackoverflow.com/questions/2882619
最满意答案
您应该可以使用
-[NSString sizeWithAttributes:]
首先为具有给定绘图属性的字符串获取边界框,然后相应地调整视图大小并进行字符串的实际绘制。You should be able to use
-[NSString sizeWithAttributes:]
to get a bounding box for the string with a given set of drawing attributes first, then size your view accordingly and do the actual drawing of the string.
相关问答
更多-
将文本容器添加到NSLayoutManager会导致异常(Adding text container to NSLayoutManager results in exception)[2023-11-07]
由于我调用了replaceLayoutManager因此发生了错误。 我改变了初始化文本视图的方式。 我没有使用init(frame: frameRect)构造函数,而是通过单独初始化文本容器来使用指定的初始化程序: var nextContainer = CASTextContainer(containerSize: containerSize) var nextView = CASTextView(frame: rect, textContainer: nextContainer) 然后我继续调用ma ... -
我想,错误报告是正确的方法。 据我所知,非连续布局给一些开发人员带来了很多麻烦,使他们再次从他们的应用程序中删除该功能。 听起来不错,看起来很难正常工作......即使对于Apple来说也是如此。 A bug report is the right way to go, I think. From what I've heard is that non-contignuous layout has caused lots of headaches to some developers making them ...
-
如何使用NSLayoutManager在CALayer中呈现文本?(How to render text in a CALayer using NSLayoutManager?)[2024-01-20]
我创建了一个自定义CALayer并覆盖了drawInContext方法,如下所示: override func drawInContext(ctx: CGContext!) { NSGraphicsContext.saveGraphicsState() var nsgc = NSGraphicsContext(CGContext: ctx, flipped: false) NSGraphicsContext.setCurrentContext(nsgc) NSColor. ... -
我发现了一种方法来完成这项工作。 在NSLayoutManagerDelegate方法didCompleteLayoutFor textContainer中:我正在检查一些段落是否在多于一个文本容器中,如果是,只需减少第一个段落的高度。 像魅力一样工作,但需要重新输出文字。 I've discovered a way to do the job. In the NSLayoutManagerDelegate method didCompleteLayoutFor textContainer: I'm che ...
-
NSLayoutManager / NSTextContainer忽略比例因子(NSLayoutManager/NSTextContainer Ignores Scale Factor)[2022-01-18]
答案结果很简单:将NSTextView添加为NSTextView的子视图,其框架与NSTextView相同。 最终的高度函数如下: -(CGFloat)calculateHeightForAttributedString:(NSAttributedString*)attributedNotes { CGFloat width = self.textView.frame.size.width; // http://www.cocoabuilder.com/archive/cocoa/54083 ... -
您应该可以使用-[NSString sizeWithAttributes:]首先为具有给定绘图属性的字符串获取边界框,然后相应地调整视图大小并进行字符串的实际绘制。 You should be able to use -[NSString sizeWithAttributes:] to get a bounding box for the string with a given set of drawing attributes first, then size your view accordingly ...
-
好吧,经过一些挖掘TextKit框架后,我终于找到了答案。 我的代码在这样的循环中工作: while ([self needsMoreColumns]) { [self addColumn]; } ... - (BOOL)needsMoreColumns { // Always create at least one column if (self.layoutManager.textContainers.count == 0) return YES; ...
-
尝试通过textview的textContainerInset调整字形rect: var glyphRect = txtView.layoutManager.boundingRectForGlyphRange(glyphRange, inTextContainer: glyphContainer!) glyphRect.origin.y += txtView.textContainerInset.top 这应该够了吧! Try adjusting the glyph rect by th ...
-
每个段落带有NSTextContainer的NSLayoutManager(NSLayoutManager with an NSTextContainer per paragraph)[2023-04-24]
我认为最简单的方法是子类NSTextContainer和覆盖 - (CGRect)lineFragmentRectForProposedRect:(CGRect)proposedRect atIndex:(NSUInteger)characterIndex writingDirection:(NSWritingDirection)baseWritingDirection remainingRect:(CGRect *)remainingRect 在自定义方法中,您将检查characterIndex的属性,并 ... -
事实证明我忘了添加 [self.textStorage addLayoutManager:self.layoutManager]; 这解决了这个问题。 It turns out I had forgotten to add [self.textStorage addLayoutManager:self.layoutManager]; That fixes the issue.