首页 \ 问答 \ 无法更改自定义字体的大小(Cannot change size of custom Font)

无法更改自定义字体的大小(Cannot change size of custom Font)

您好我使用下面的代码为标签文本使用自定义字体样式。 我安装它并且工作正常,但问题是文本的大小不会改变。 我尝试了不同尺寸的次数。 我不知道该怎么做

self.saveButton_label.text = NSLocalizedString(@"Saved", nil);
self.saveButton_label.font = [UIFont fontWithName:@"Helvetica Neue LT Pro" size: 13.0];

Hi I am using below code to use custom font style for label text. I've installed it and work fine but the problem is that the size of text does not change. I've tried more times with different sizes. I don't know what should do

self.saveButton_label.text = NSLocalizedString(@"Saved", nil);
self.saveButton_label.font = [UIFont fontWithName:@"Helvetica Neue LT Pro" size: 13.0];

原文:https://stackoverflow.com/questions/23011461
更新时间:2022-12-26 06:12

最满意答案

将javascript代码放在视图中是不好的做法,更不用说部分视图了。 因此,我建议您在单独的javascript文件中将此javascript代码外部化为单独的函数。

然后你可以订阅Ajax.BeginForm帮助器的OnSuccess事件:

@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "editSuccess", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
{
    ...    
}

然后在单独的 javascript文件中定义editSuccess函数:

function editSuccess(result) {
    alert('hi');
}

现在在你的局部视图中,你应该只留下部分标记中的内容。 摆脱任何<script>标签,你不需要它们。 您不需要任何内联脚本。 它们只会增加网页的大小并浪费带宽,因为它们无法被浏览器缓存:

@model Test.Models.CARE
<h2 style="padding: 0px; margin-top: 0px;">Edit</h2>
@using (Html.BeginForm("SaveForConfirmation", "Home"))
{
    ...
}

更新:

如果你有一些写得不好的javascript,它依赖于局部内部的ViewBag这样的垃圾,那么你可以在OnSuccess回调中调用相应的函数:

@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "s", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
{
    ...    
}

注意我是如何定义OnSuccess = "s" ,其中s是你在partial中定义的函数,在这种情况下将调用它。 但我再次重申,这是一种错误的方法,只有在你没有时间正确重构代码时才应该使用它。


It's bad practice to put javascript code in views, let alone partial views. So I would recommend you to externalize this javascript code in a separate function in a separate javascript file.

And then you could subscribe to the OnSuccess event of the Ajax.BeginForm helper:

@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "editSuccess", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
{
    ...    
}

and then define the editSuccess function in a separate javascript file:

function editSuccess(result) {
    alert('hi');
}

now in your partial view you should leave only what is supposed to be in a partial - markup. Get rid of any <script> tags, you don't need them. You don't need any inline scripts. They only increase the size of your webpages and waste bandwidth as they cannot be cached by the browsers:;

@model Test.Models.CARE
<h2 style="padding: 0px; margin-top: 0px;">Edit</h2>
@using (Html.BeginForm("SaveForConfirmation", "Home"))
{
    ...
}

UPDATE:

If you have some poorly written javascript that depends on crap like ViewBag inside the partial then you could invoke the corresponding function from within the OnSuccess callback:

@using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "s", UpdateTargetId = "content", InsertionMode = InsertionMode.Replace }))
{
    ...    
}

Notice how I have defined OnSuccess = "s" where s is the function that you have defined in your partial and which will be invoked in this case. But I repeat once again, this is a wrong approach and should only be used if you don't have time to refactor your code properly.

相关问答

更多
  • if(!$msg > 0) { echo trim('no'); } 应该 if !($msg > 0) { echo trim('no'); } 否则,你是否定$ msg中的值。 如果这是0,它变成1,如果它是1,它变成0.(基本否定布尔值)。 所以1和0都不会大于0,因此它不会echo trim('no'); 。 但基本上你可以检查$msg是否等于零,如: if ($msg == 0) { echo trim('no'); } else { } if(!$msg ...
  • 首先,AjaxResponse对象具有setData()方法而不是setContent() 。 要通过Drupal模块实际订阅某人mailchimp,您可以使用主mailchimp模块中的mailchimp_subscribe()函数。 My "working" solution now is: alter the form block, add an ajax callback function, prevent click and adds some ajax progress visualizatio ...
  • 如果您使用Ajax,则必须在JavaScript代码中处理它以更改视图。 在控制器中使用它将数据传递给Ajax调用(替换虚拟哈希): render json: { test: "hello" } 在您的ajax的成功函数中,我刚才渲染的JSON对象可以在函数的data参数中访问。 现在我必须使用javascript操纵视图 编辑: 要回答你的编辑,我猜你有一些字符在你的JSON中处理起来比较复杂,比如中文,土耳其语......也许这可能对你有所帮助: 编码:: UndefinedConversionErr ...
  • PHP脚本发回空白和一个新行,因此,即使控制台输出正确的返回字符串,它不符合if语句。 我的PHP脚本顶部的包含在?>结束标记之后有两个额外的空白行。 删除之后,响应现在是正确的,并且满足Ajax调用的if语句。 The php script was sending back whitespace and a new line hence why even though the console was outputting the correct return string it wasn't satisf ...
  • 将javascript代码放在视图中是不好的做法,更不用说部分视图了。 因此,我建议您在单独的javascript文件中将此javascript代码外部化为单独的函数。 然后你可以订阅Ajax.BeginForm帮助器的OnSuccess事件: @using (Ajax.BeginForm("Edit", "Home", new AjaxOptions { OnSuccess = "editSuccess", UpdateTargetId = "content", InsertionMode = Inser ...
  • 在您的JS文件中,删除contentType: "application/json", 在您的php文件中,选中“include file url”和 关闭if语句是否正确阻止 JS档案: let CurrentDate = Date(); jsonObject = { 'TrackName' : 'Material Science', 'TrackDesc' : 'Test Text Test Text Test Text Test Text Test Text Test Text Test ...
  • 从html内容中单独加载脚本,可以使用$ .getScript()。 It happens because of the document.write call. Here's some info on what's going on: Writing After A Page Has Been Loaded If document.write() is invoked after a page has finished loading, the entire static (non-script gene ...
  • 我在@ zaporylie提供的另一个网站上获得了解决方案。 问题不是AJAX,而是我解决问题的方法。 简而言之,他建议创建一个依赖于PhantomJS Capture的新自定义模块,然后声明一个块。 这是AJAX的工作代码: phantomjs_capture_block.info name = PhantomJS Capture Block description = Adds block with simple form. core = 7.x package = Other dependencies ...
  • 就像错误说的那样,你有一个SyntaxError 。 固定代码是: $.ajax({ url: "pull_overview", dataType: "json", cache: false, success: function (data) { if (data == null) { $('#ajax-loader').hide() $('#overviewlist tbody').append("

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)