我无法在XCode中为UILabel设置自定义字体.
这就是我尝试过的:
下载"JennaSue"字体 - http://www.dafont.com/jenna-sue.font
在"支持文件"文件夹下打开"app-info.plist"
使用"应用程序提供的字体"键在列表中添加新行
在这个数组中添加"JennaSue.ttf"
在这样的代码中使用它:
self.someLabel.font = [UIFont fontWithName:@"JennaSue" size:14];
没有任何反应 - 默认字体是可见的.
为什么?我究竟做错了什么?我该如何解决?
假设我有以下代码:
#include <boost/filesystem/path.hpp>
#include <boost/thread.hpp>
void foo()
{
const boost::filesystem::wpath& appdata_folder = std::getenv("APPDATA");
while (true)
{
boost::this_thread::sleep_for(boost::chrono::milliseconds(500));
}
}
int main()
{
boost::thread first(foo);
boost::thread second(foo);
first.join();
second.join();
}
Run Code Online (Sandbox Code Playgroud)
它在运行时失败,并显示以下错误:
* Internal Program Error - assertion (codecvt_facet_ptr()) failed in const class std::codecvt &__cdecl boost::filesystem::path::codecvt(void): libs\filesystem\src\path.cpp(888): codecvt_facet_ptr() facet hasn't been properly initialized
In the documentation I read that it's not thread-safe in terms of parallel set and get operations, not the several get operations as in my case. _wgetenv function works …
我需要为UINavigationController整个应用程序的条形图设置背景图像,所以我写了下面的代码:
func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject : AnyObject]?) -> Bool {
let backgroundImage = UIImage(named: "NavBar")
UINavigationBar.appearance().setBackgroundImage(backgroundImage, forBarMetrics: .Default)
return true
}
Run Code Online (Sandbox Code Playgroud)
但是我需要UIImage调整条形的大小,因为在我的情况下,它太大而且不适合整个条形.我该怎么做?
提前致谢.
为什么以下代码在我写"2.01"和时给出了不同的结果"2.02"?
#include <boost/lexical_cast.hpp>
#include <iostream>
#include <string>
int main()
{
const std::string str = "2.02";
try
{
const double b = boost::lexical_cast<double>(str) * 100.0;
std::cout << "double: " << b << '\n';
const int a = boost::lexical_cast<int>(b);
std::cout << "int: " << a << '\n';
}
catch (const std::exception& ex)
{
std::cerr << ex.what() << '\n';
}
}
Run Code Online (Sandbox Code Playgroud)
产量
double: 202
int: 202
Run Code Online (Sandbox Code Playgroud)
但是,如果我改变"2.02"到"2.01"它给了我下面的输出:
double: 201
bad lexical cast: source type value …Run Code Online (Sandbox Code Playgroud) 有没有办法使用 Swift 在 Mac OS 中捕获全局按键(即使我的应用程序未处于活动状态)?
提前致谢。
我想为 WinForms 应用程序中任何线程的所有未处理异常设置处理程序方法。我自己不创建任何应用程序域。
根据UnhandledException文档,我也需要UnhandledExceptionMode.ThrowException通过方法设置模式Application.SetUnhandledExceptionMode来捕获主线程的异常:
在使用 Windows 窗体的应用程序中,主应用程序线程中未处理的异常会导致引发 Application.ThreadException 事件。如果处理此事件,则默认行为是未处理的异常不会终止应用程序,尽管应用程序仍处于未知状态。在这种情况下,不会引发 UnhandledException 事件。可以通过使用应用程序配置文件或在挂接 ThreadException 事件处理程序之前使用 Application.SetUnhandledExceptionMode 方法将模式更改为 UnhandledExceptionMode.ThrowException 来更改此行为。这仅适用于主应用程序线程。UnhandledException 事件是针对其他线程中抛出的未处理异常而引发的
因此,生成的代码将如下所示:
public static void UnhandledExceptionEventHandler(object sender, UnhandledExceptionEventArgs e)
{
// ...
}
[STAThread]
static void Main(string[] args)
{
Application.SetUnhandledExceptionMode(UnhandledExceptionMode.ThrowException);
AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(UnhandledExceptionEventHandler);
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new MainForm(pathToCheck));
}
Run Code Online (Sandbox Code Playgroud)
可以吗?它会捕获来自任何线程(包括主线程、UI 线程和Task类创建的所有线程)的所有未处理的异常吗?我正确理解了文档吗?
是的,我在这里看到了这样的问题,但我不明白为什么我还应该使用以下代码:
Application.ThreadException += new
ThreadExceptionEventHandler(ErrorHandlerForm.Form1_UIThreadException);
Run Code Online (Sandbox Code Playgroud) 是否有Finalizer比这更通用的方法来编写一个类?
#include <functional>
#include <iostream>
template <typename T>
class Finalizer
{
public:
Finalizer(const std::function<T>& f) : _f(f) {}
~Finalizer()
{
_f();
}
private:
std::function<T> _f;
};
int main()
{
Finalizer<void()> finalizer([]() { std::cout << "str" << std::endl; });
}
Run Code Online (Sandbox Code Playgroud)
我想摆脱手动类模板参数规范,以便能够编写如下代码:
Finalizer finalizer([]() { std::cout << "str" << std::endl; });
Run Code Online (Sandbox Code Playgroud)
可能吗?
是否保证此代码
function runEmbeddedJSInPageEnvironment(code) {
var e = document.createElement('script');
e.type = 'text/javascript';
e.appendChild(document.createTextNode(code));
(document.head || document.documentElement).appendChild(e);
e.parentNode.removeChild(e);
}
runEmbeddedJSInPageEnvironment("$('#someform').off('submit');");
Run Code Online (Sandbox Code Playgroud)
将等待传递给的代码runEmbeddedJSInPageEnvironment先完成,然后通过调用removeChild函数将其从页面中删除?
或者可以在此代码执行完毕之前将其删除?
我有一个std::string类的对象,我需要传递给C函数,char*通过迭代它并搜索空终止符号来操作缓冲区.
所以,我有这样的事情:
// C function
void foo(char* buf);
// C++ code
std::string str("str");
foo(&str[0]);
Run Code Online (Sandbox Code Playgroud)
假设我们使用C++ 11,因此我们保证std::string表示将具有连续存储的字符.
但我想知道是否有任何保证&str[0]会指向缓冲区结束\0?是的,有c_str成员函数,但我在谈论operator[].
有人可以引用标准吗?