Posts

Swift: Make part of text bold

Image
 Hello everyone, You may have encountered situations where you want to display part of your label's string as bold, while keeping the other part as normal. It's very easy using an attributed string. Below is the code that you need to accomplish this. let attrs = [ NSAttributedString . Key . font : UIFont (name: <your custom font name> , size: <your font size> )] let attributedString = NSMutableAttributedString (string:boldText, attributes:attrs as [ NSAttributedString . Key : Any ]) let normalText = normalText let normalString = NSMutableAttributedString (string:normalText) attributedString. append (normalString)          Now, set the attributed string to your UILabel instance. E.g someLabel . attributedText = attributedString That's it. You can play around with this and see how you can achieve other results with the attributed Strings!

Plist find error (Xcode, iOS)

If you have edited a Plist file on your own, it sometimes might not work after adding back to the Xcode project. Finding the error can be cumbersome. However, Macs come with a great tool called plutil . You can directly run it from the command prompt. Just run plutil E.g: plutil /Desktop/MyApp/myplistfile.plist You can easily figure out where the issue is after running the command.

Most useful terminal commands

Below is a list of mostly helpful terminal commands you'd need to get on with your work. I'm planning to keep adding entries to this list later. Print environment variable echo $ E.g:  echo $PATH   would print the PATH variable value Mac Show current Xcode location xcode-select --print-path Print current path (working directory) pwd Perform Load testing (Using Apache AB) You can easily perform a simple load test using Apache AB. Macs come with apache AB installed. You can directly run from the terminal. ab -n  -c E.g:  ab -n 100 -c 5 http://www.google.com/

kSoap2 printing request dump

Hi, kSoap2 is a library for SOAP which is used in Androids. Here's a neat little trick, if you want to see the actual XML sent received. 1. Set httpTransport.debug=true; before making the call 2. Read values from the httpTransport object afterwards String s1 = httpTransport.requestDump; String s2 = httpTransport.responseDump; Have fun !!!

iOS Split Video into frames

Dear all, You may have encountered scenarios where you would like to split a video into several frames at different time intervals. This post is for you if you intend to do the splitting at device level. I presume that you have some reasonable experience with Objective C and XCode such as adding a framework and adding a file. There are several steps to do to get this going. 1. Build an XCode project and add a video file to project. I've worked with .mp4 files. Should work with other standard formats. 2. Add AssetsLibrary framework and AVFoundation frameworks to your project 3. Create a AVAsset object with your video. You need to pass the location of the video as a NSURL object. I added the video(myvid.mp4) as an asset to my project. Therefore, I will use the following method to create the asset object. AVAsset *asset=[AVAsset assetWithURL:[NSURL fileURLWithPath:[[NSBundle mainBundle] pathForResource:@"myvid" ofType:@"mp4"]]]; NOTE: If you ne...

iOS 7 UISearchBar Issue

Dear all, Transition into iOS 7 introduces a lot of adjustments. One such adjustment is the UISearchBar. If you try to set the UISearchBar to the NavigationBar inside a UIViewController, then it will not work correctly in iOS 7. The workaround for that is to use a UISearchDisplayController. Here are the steps. 1. Create your UISearchBar UISearchBar *newSearchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 0, 320, 44)]; newSearchBar.showsCancelButton=YES; newSearchBar.delegate=self; 2. Create a UISearchDisplayController and initialise with the UISearchBar & your ViewController UISearchDisplayController *searchDisplayController=[[UISearchDisplayController alloc] initWithSearchBar:newSearchBar contentsController:self]; 3. Set the datasource & delegates of the UISearchDisplayController searchDisplayController.delegate=self;//The delegate of UISearchDisplayController searchDisplayController.searchResultsDataSource=self;//The data source for the search res...

Crittercism "is this an employee-facing app" meaning

Hi all, Crittercism is very useful in many of our developments. If you have tried to make a new app with Crittercism, they ask you a question "Is this an employee facing app". Apparently, there seems to be no definition and I couldn't figure it out even with the help of my teammates. So, I asked Crittercism myself and here is their explanation. "The question is asked to find out whether your application will be published in the App Stores for anyone to download (B2C) or whether they will be used internally within your organization or company by employees only (B2E)." Hope this helps you too :)

Android Multi format TextView

Hey Androids !!! This is going to be my very first post on Android development. You may know that I've written many posts on Dot Net, Java & iPhone. From today onwards, I will add Android to that list :) So, if you're in a situation that you need to have a single label(TextView) with multiple formats, then this will be the post for you. It becomes very simple when you know a bit of html. Here is a list of tags supported by Android TextView before you get started. Have a look at this before you start. Suppose you have a TextView named multiFormatView TextView multiFormatView; The first step is to build your HTML string. String htmlString = "<b>This is bold</b>"+"And this is not."; Now there is only one line of code. Just set the text to the TextView using. multiFormatView .setText(Html.fromHtml(htmlString)); That's it. So, it will print  This is bold. And this is not. You can juggle around with each o...

XCode importing a file to whole project

Hi, Sometimes you may encounter situations where you have a file which is used frequently throughout the XCode project. This may be a configurations file which is used in 80% of your code files. Importing this in each file is a certain possibility(and the very normal way with no issues), but if you are lazy and just want to add it in one place, this is the post for you. If you analyze the project, there is a file named <project-name>.pch. There is a block of code which has the following. #ifdef __OBJC__     #import < UIKit/UIKit.h>     #import < Foundation/Foundation.h> #endif NOTE: As you can see, UIKit is already added and so is the Foundation framework. That is why you can use classes such as "UIView" or "NSArray" without any additional imports in your code file. That's just an extra bit of info for the curious !!!. So, likewise, we can add our commonly used file into that block as well in the following manner. #i...

iOS Convert Seconds into hours,minutes and seconds

Hi all, In building iPhone applications you may have come across situations that you count some time in seconds, but wish to let the user view it in a more readable format such as 1 hour 38 minutes and 44 seconds. Here is a piece of code that I wrote if you need to get this done in your code. - ( NSString *)timeFormatted:( int )totalSeconds {     int seconds = totalSeconds % 60 ;     int minutes = (totalSeconds / 60 ) % 60 ;     int hours = totalSeconds / 3600 ;         NSString *timeString =@"";     NSString *formatString=@"";     if(hours > 0){         formatString=hours==1?@"%d hour":@"%d hours";         timeString = [timeString stringByAppendingString:[NSString stringWithFormat:formatString,hours]];     }     if(minutes > 0 || hours > 0 ){         formatString=minutes==1?@" %d minute...

Mac Audio Convert Tool

Hi guys. It's really painful when you need to have a soundtrack in one format when you have another format. I found this really useful tool named SoX for Mac OS which you can download free from here .

iPhone manually set Cookies

Hi guys !!! You may have encountered situations where you wish to set some cookies through your app code. There is a very basic procedure to do it. 1. Create a dictionary with all the cookie properties 2. Create a Cookie passing the property dictionary which you created 3. Set the Cookie using the NSHTTPCookieStorage class First create a properties dictionary. NSDictionary *propertiesUsername = [ NSDictionary dictionaryWithObjectsAndKeys :                                         @".yourdomain.com" , NSHTTPCookieDomain ,                                         @"cookie_name" , NSHTTPCookieName ,                                         @"cookie_value" , NSHTTPCo...

JavaScript library for Date formatting

Hi all, You must have faced situations where you need to convert a date string to a different object. The usual procedure is to first parse the string into a Date object of that language, specifying your formatting string. The next step is to convert the Date object back into a string specifying the new formatter. In order to do this in JavaScript, I came across two libraries which I thought to share with you. Moment.js which is freely distributable under the MIT license. You can download it from here . There are two versions. You can download the minified source if you need to save space. The following example shows how to use it to convert from one format to another. First include the javascript in your files. var oldFormatTime = moment('2012-10-01','YYYY-MM-dd'); var newFormatTime = oldFormatTime.parse('d-MM-YYYY'); So, the final output would be 1-10-2012 In addition to this, I also found the following library. Datejs is an open source ...

View iCloud Files via Browser

Here is a neat little way to browse all the files on your iCloud account. Simply Browse iCloud Files  using this link. Cheers !!!

Show/Hide Mac Hidden Files

Hi all, You might need to view hidden files on a mac at times. Here is the command which you can use to view hidden files on a mac. Open a terminal window and type the following command and press return. defaults write com.apple.Finder AppleShowAllFiles TRUE After that, you need to restart your Finder to make the changes visible. killall Finder Now you can view all the hidden files. If you want to hide the hidden files back to the original settings, simply run the same command with parameter to FALSE defaults write com.apple.Finder AppleShowAllFiles FALSE Again restart the finder by typing killall Finder That's all for now folks :)

Convert wav file to caf file Mac

Hi all, Here is a command which you can use on the mac to convert a wav file to caf file. afconvert -f caff -d LEI16@44100 -c 1 inputMusic.wav outputMusic.caf Here is the  Link to Stack Overflow thread  where I found this from :)

iPhone SDK: Create .ipa file from Corona Build

Hi all !!! After a long time, I thought of putting a post on blogger. Suppose you simply have the build file from an iPhone project, and needs to build a .ipa file from it. It is very simple, if you have the project source code. But, suppose you only have the build, but needs to build a .ipa file from it. You will face this situation if you use Corona SDK for building games etc. Even so, there is a workaround for this. After receiving the build make a folder and name it to "Payload". Put the build inside it and zip it. Then simply rename it to "<projname .ipa>". Now you should be able to use the .ipa file as normal.

Send Gmail using Dot NET

Hi, in my previous posts, I have posted how to send mail using the Java API. In this section, I would like to demonstrate on how to send mail using Dot NET. Using Dot NET, it is equally easy to send mail. In this post I would use my Dot NET application to connect with Google's outgoing mail server (Google's SMTP server) and use that to forward my mail. (In my previous post, I've demonstrated on sending mail using my own SMTP server which ran on my machine. In this scenario, it will directly put the outgoing message into the Gmail's SMTP server) You will be using mainly few Classes to get the job done. System.Net.Mail.MailMessage System.Net.NetworkCredential System.Net.Security.SmtpClient These classes will provide the basic methods to get the job done. You will also be using System.Net.Mail.MailAddress class. (Though there is a way to get the job done without actually needing this.) First of all, you need to import the namespaces. using System....

Download File using Dot Net

In this post, I will demonstrate how easy it is to download a file from a web server to your local hard drive. In most scenarios, you may browse the net using your web browser and click on a hyperlink to start a downloading of a file from a remote site. Some of you may be interested in how to download this using their application code using Dot Net. This can be very easily achieved using the WebClient class under System.Net namespace. First, import the System.Net namespace. using System.IO; The above LOC will do so. Now, create an instance of WebCleient class. WebClient client = new WebClient(); Now, call the DownloadFile method client.DownloadFile(<url>, @"<fileDestinationName>.<filetype>"); Have fun. Cheers !!!!

ASP Response.Write newline

Hi, all of you who have used ASP may have encountered situations where you require to write a text output to the screen. It can be easily done by using Response.Write("Hello world"); However, if you wish to append some more text to a newline, it would not work in the following ways. Response.Write("Hello world \n"); Response.Write("Good day."); The output of the above lines would be Hello world Good day. and NOT Hello world Good day. In order to overcome this, you can very simple place an html break tag inside the code. Response.Write("Hello world"); Response.Write("<br/>"); Response.Write("Good day."); The output would be the following. Hello world Good day. Cheers !!!