在Xamarin.iOS中实现TextLayer的垂直对齐
代码如下:
public class SHLCTextLayer : CATextLayer {
public SHLCTextLayer(IntPtr handle) : base(handle) {
}
public SHLCTextLayer() : base() {
}
public SHLCTextLayer(NSCoder coder) : base(coder) {
}
public SHLCTextLayer(NSObjectFlag t) : base(t) {
}
public override void DrawInContext(CGContext ctx) {
try {
var height = this.Bounds.Size.Height;
var fontSize = this.FontSize;
var yDiff = (height - fontSize) / 2 - fontSize / 10;
ctx.SaveState();
ctx.TranslateCTM((nfloat)0.0f, yDiff);
base.DrawInContext(ctx);
ctx.RestoreState();
} catch (Exception e) {
ErrorReporter.Report(e);
}
}
}
- 原文作者:岁寒
- 原文链接:http://www.suihanime.com/post/Xamarin/%E5%9C%A8Xamarin.iOS%E4%B8%AD%E5%AE%9E%E7%8E%B0TextLayer%E7%9A%84%E5%9E%82%E7%9B%B4%E5%AF%B9%E9%BD%90/
- 版权声明:本作品采用知识共享署名-非商业性使用-禁止演绎 4.0 国际许可协议进行许可,非商业转载请注明出处(作者,原文链接),商业转载请联系作者获得授权。