Tutorial by Examples

Initialize the UITextField with a CGRect as a frame: Swift let textfield = UITextField(frame: CGRect(x: 0, y: 0, width: 200, height: 21)) Objective-C UITextField *textField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 200, 21)]; You can also create a UITextField in Interface Builde...
Given below is a simple example to train a Caffe model on the Iris data set in Python, using PyCaffe. It also gives the predicted outputs given some user-defined inputs. iris_tuto.py import subprocess import platform import copy from sklearn.datasets import load_iris import sklearn.metrics ...
Flyweight is one of structural design patterns. It is used to decrease the amount of used memory by sharing as much data as possible with similiar objects. This document will teach you how to use Flyweight DP properly. Let me explain the idea of it to you on a simple example. Imagine you're working...
Line Length // Lines should never exceed 100 characters. // Instead, just wrap on to the next line. let bad_example = "So this sort of code should never really happen, because it's really hard to fit on the screen!"; Indentation // You should always use 4 spaces for indentation. ...
Preludes and Re-Exports // To reduce the amount of imports that users need, you should // re-export important structs and traits. pub use foo::Client; pub use bar::Server; Sometimes, crates use a prelude module to contain important structs, just like std::io::prelude. Usually, these are impor...
You should order your imports and declarations like so: extern crate declarations use imports External imports from other crates should come first Re-exports (pub use)
As your activity begins to stop, the system calls onSaveInstanceState() so your activity can save state information with a collection of key-value pairs. The default implementation of this method automatically saves information about the state of the activity's view hierarchy, such as the text in an...
Fragments also have a onSaveInstanceState() method which is called when their state needs to be saved: public class MySimpleFragment extends Fragment { private int someStateValue; private final String SOME_VALUE_KEY = "someValueToSave"; // Fires when a configuration ch...
In many cases, we can avoid problems when an Activity is re-created by simply using fragments. If your views and state are within a fragment, we can easily have the fragment be retained when the activity is re-created: public class RetainedFragment extends Fragment { // data object we want to ...
If you want to lock the screen orientation change of any screen (activity) of your android application you just need to set the android:screenOrientation property of an <activity> within the AndroidManifest.xml: <activity android:name="com.techblogon.screenorientationexample.Main...
If your application doesn't need to update resources during a specific configuration change and you have a performance limitation that requires you to avoid the activity restart, then you can declare that your activity handles the configuration change itself, which prevents the system from restartin...
- (UIImage *)getSnapshot { UIScreen *screen = [UIScreen mainScreen]; CGRect bounds = [self.view bounds]; UIGraphicsBeginImageContextWithOptions(bounds.size, false, screen.scale); CGContextRef context = UIGraphicsGetCurrentContext(); CGContextSetInterpolationQuality(context, kCGInterpola...
The CAEmitterLayer class provides a particle emitter system for Core Animation. The particles are defined by instances of CAEmitterCell. The particles are drawn above the layer’s background color and border. var emitter = CAEmitterLayer() emitter.emitterPosition = CGPoin...
For example we will create view that contains emitter layer and animates particles. import QuartzCore class ConfettiView: UIView { // main emitter layer var emitter: CAEmitterLayer! // array of color to emit var colors: [UIColor]! // intensity of appearance var ...
Demonstrate how to embed a lua interpreter in C code, expose a C-defined function to Lua script, evaluate a Lua script, call a C-defined function from Lua, and call a Lua-defined function from C (the host). In this example, we want the mood to be set by a Lua script. Here is mood.lua: -- Get versi...
To setup a WebRTC-based communication system, you need three main components: A WebRTC signaling server To establish a WebRTC connections, peers need to contact a signaling server, which then provides the address information the peers require to set up a peer-to-peer connection. Signaling serv...
Suppose you have multiple threads running. Each thread is doing one task. You want to get notified either on the mainThread OR another thread, when all the task-threads are completed. The simplest solution to such a problem is a DispatchGroup. When using a DispatchGroup, for each request, you ente...
Validation attributes can be used to easily configure model validation. public class MyModel { public int id { get; set; } //sets the FirstName to be required, and no longer than 100 characters [Required] [StringLength(100)] public string FirstName { get; set; } } Th...
You can create your own queue using dispatch_queue_create Objective-C dispatch_queue_t queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_SERIAL); Swift // Before Swift 3 let queue = dispatch_queue_create("com.example.myqueue", DISPATCH_QUEUE_SERIAL) // ...
You can add an image to a view's layer simply by using its contents property: myView.layer.contents = UIImage(named: "star")?.CGImage Note that the UIImage needs to be converted to a CGImage. If you wish to add the image in its own layer, you can do it like this: let myLayer = CA...

Page 628 of 1336