UITextView autoSize(UITextView autoSize)
我认为这将是一件容易的事,因为人们会经常想要这样做,但我已经四处寻找并尝试了不同的方法,但似乎没有任何效果。
我想要做的就是创建一个包含两行Text的UITextView。
如果文本太长,并且进入3行,我想自动调整字体,直到它适合2行。
从概念上讲,我打算做一个递归函数,不断缩小文本,直到它适合两行(基于文本字段的高度),但我无法将它拉下来。
任何建议都非常感谢。
I would think this would be an easy thing since people would want to do it often, but I've searched around and tried different approaches, but nothing seems to work.
All I want to do is create a UITextView that has two lines of Text.
If the text is too long, and goes into 3 lines, I want to autosize the font until it fits into 2 lines.
Conceptually, I was planning on doing a recursive function that keeps shrinking the text until it fits on two lines (based on the height of the text field), but I couldn't pull it off.
Any suggestions are greatly appreciated.
原文:https://stackoverflow.com/questions/4696526
最满意答案
library(ggplot2) set.seed(123) d <- data.frame(x = rnorm(1000)) ggplot(d, aes(x)) + stat_bin(geom = "point", aes(y = ..density..), #same breaks as function hist's default: breaks = pretty(range(d$x), n = nclass.Sturges(d$x), min.n = 1), position = "identity") + stat_function(fun = dnorm, col = "red") + scale_y_log10(limits = c(0.001, 10))
library(ggplot2) set.seed(123) d <- data.frame(x = rnorm(1000)) ggplot(d, aes(x)) + stat_bin(geom = "point", aes(y = ..density..), #same breaks as function hist's default: breaks = pretty(range(d$x), n = nclass.Sturges(d$x), min.n = 1), position = "identity") + stat_function(fun = dnorm, col = "red") + scale_y_log10(limits = c(0.001, 10))
相关问答
更多-
答案似乎是,你做不到。 有一个预定义的顺序,其中ggplot2进行转换; 秤 统计 坐标 因此,不使用比例变换,而是使用坐标变换。 base + stat_function(fun = dexp, colour = "red") + coord_trans(x = "log10") The answer seems to be, you can't. There is a predefined order in which ggplot2 does transformations; Scales Stat ...
-
以下似乎工作,虽然它对我来说仍然感觉非常hacky: data$fit <- ... # evaluate function on Date relrows <- (start_date <= data$Date) & (data$Date <= end_date) p1 <- p1 + annotate("line", y=data$fit[relrows], x=data$Date[relrows]) The following seems to work, though it still feel ...
-
如副本中所示,将标签移动到数据集会绕过aes中延迟评估的问题。 您可以通过首先在函数中创建数据集并在循环中将适当的labels值添加到数据集中作为新变量来实现此目的。 您可以将此数据集用于stat_function的data参数。 plot.linear.equations <- function(X, ...){ dat <- data.frame(x = X) p <- ggplot(mapping = aes(x = X)) arguments <- list(... ...
-
这不是一个stat_function问题。 你没有一个名为y的列,你传递给ggplot函数的数据集。 更改data参数值可以解决问题。 ggplot(plotdata, aes(x, y)) + geom_line() + stat_function(mapping = aes(x = x), data=plotdata, fun = xey, linetype = 2) This isnt a stat_function issue. You dont have a column called y th ...
-
我想到了另一个天真的解决方案:预测每个dlnorm()的值。 ## Split up the data according to t tt <- split(test, test$t) ## Fit a lognormal to every dataset fits <- lapply(tt, function(x) fitdistr(x$int, "lognormal")) ## Predict values fitted <- lapply(fits, function(x) dlnor ...
-
library(ggplot2) set.seed(123) d <- data.frame(x = rnorm(1000)) ggplot(d, aes(x)) + stat_bin(geom = "point", aes(y = ..density..), #same breaks as function hist's default: breaks = pretty(range(d$x), n = nclass.Sturges(d ...
-
将stat_function图层添加到ggplot2中的geom_point(Adding a stat_function layer to a geom_point in ggplot2)[2023-09-05]
是的,你的y截距分别是565和286 ,但这些值是x=0时的值。 您在问题中显示的图表从x=55左右开始。 在这种情况下,当我们为您的函数插入x=55 ,我们得到: -2.129(55^3) - 23.456(55) + 565 = 354,937.455 286 + -0.997*(55^3) = 165,589.875 所以你的想法是你的y拦截实际上并非如此。 我认为stat_functions工作正常。 如果您不喜欢结果,我认为您需要重新考虑要绘制的函数。 Yes, your y-intercepts ... -
尝试这个: df.new=data.frame(x=seq(20,60,0.1), y=coef(my.nls)[1]*(-exp(seq(20,60,0.1))+coef(my.nls)[2])) d4+geom_line(aes(Temp.,y,group=NULL),data=df.new)+ xlim(20,60)+ylim(-.1,1) 问题是stat_function(...)在默认数据集df给出的范围内计算x的函数。 由于max(df$temp.) = ...
-
使用stat_function在ggplot2中绘制部分阴影的正常曲线(Using stat_function to draw partially shaded normal curve in ggplot2)[2023-03-04]
传递给stat_function的函数必须是未stat_function (除非它返回另一个函数;类似于purrr::partial之类的副词或类似的另一种方法),因为stat_function需要传递x值的向量。 你已经完成了dnorm你需要用dnorm做什么:通过args传递额外的固定参数: library(ggplot2) score = 1800 m = 1500 std = 300 funcShaded <- function(x, lower_bound) { y = dnorm(x ... -
问题是你的loglikelihood函数。 您必须将“矢量化”函数传递给stat_function。 如果传入向量,R中的大多数函数将返回向量。 例如, sin(1:10 )将返回数字1到10的正弦。但是,当向量函数传递给值时,只返回一个值 loglikelihood(seq(-5,5, by=.1), df) # [1] -20534.44 由于它的行为不像“普通”R函数,因此存在此问题。 解决此问题的最简单方法是将您的函数定义包装在Vectorize命令中。 守 vloglikelihood <- V ...