قالب وردپرس درنا توس
Home / Mac / 5 Build Your Own PDF Reader 3 – The Eclectic Light Company

5 Build Your Own PDF Reader 3 – The Eclectic Light Company

Follow your enthusiastic comments on the first two parts of my demo PDF Reader app, here's the third part of two that shows you how to customize it in Xcode to show your documents the way you want.

Open the project in Xcode and increase the version number here, here to 1.0b2 .


It is up to you how to manage and format these but not build a new version to use without giving it a new number. It can be confusing as to where this appears in all project settings: finally to the left of the window, select project at the top, and in the view select sidebar Target, ] then click General element above.

Change window and display sizes

Most of the work in this article should be performed in Interface Builder (IB), then select Main.storyboard and in the interface view, select the window [19659007] located above View Controller . Select Size Inspector in the top right and you will see the first window size. Change Width and Height to several useful initials, such as 600 x 600 .

"srcset =" https://eclecticlightdotcom.files.wordpress.com/2019/02/pdfdemo31.jpg?w=940 940w, https: //eclecticlightdotcom.files.wordpress .com / 2019/02 / pdfdemo31.jpg? w = 1878 1878w, https://eclecticlightdotcom.files.wordpress.com/2019/02/pdfdemo31.jpg?w=150 150w, https: //eclecticlightdotcom.files.wordpress .com / 2019/02 / pdfdemo31.jpg? w = 300 300w, https://eclecticlightdotcom.files.wordpress.com/2019/02/pdfdemo31.jpg?w=768 768w, https: //eclecticlightdotcom.files.wordpress .com / 2019/02 / pdfdemo31.jpg? w = 1024 1024w "sizes =" (max width: 940px) 100vw, 940px "/>

To enter a minimum window size, check Minimum content size You can find the default values ​​copied to it. If you have controls that need a minimum size window, this is very useful, b Out here is probably not necessary.

When you set them, the displayed window grows and overlap View Cont roles below. Pull it up so that they are adjacent to each other and then select View Controller .

No matter where you click in View Controller, you will probably choose one of the deeper objects rather than See yourself, so in the left sidebar, click View just below the top of the object hierarchy .


Change its Width and Height to match the windows, in my case 600 ] x 600 . Again, when it is changed, drag the viewer control over the window so that they do not overlap.

Note that the objects in the window have automatically changed the size to fill it, as they already have full authorization turned on. Where you work with a more complex dialogue with anchored fixed-size objects, like buttons, you probably have to adapt them now.

At this point, you may need to adjust the constraints by removing them all and then reapplying them. But in this case, because the constraints are simple, you don't have to.

Changing Thumbnail View

You can also adjust the width of the thumbnail display. The best way to do this is to select Split View then click once or twice on the divider until the pointer changes and you can drag it. When you think you have the correct width, select Thumbnail and check the width. Here I bet on 134 which is slightly more than 128, which is the intended width of the page thumbnails.


With the thumbnail view selected, switch to Attribute Inspector and adjust The thumbnail size at the top, here to 128 x 128 .

At this time, the thumbnail view lets you drag thumbnails around to reshape the pages. You may want to disable it as you do not save the modified PDF. It is up to you.


Still in Attribute Inspector, select PDFView yourself, and look at the options there. Do not worry about scaling, as we specify what is to be scaled automatically in the code. For many of these options, you can set them either in IB or in your code.


The other inspector you sometimes need to use is Connection Inspector . With PDFView still selected, click the Connection inspector to see links to and from that view.


The only one shown as connected should be in Reference Receivers, to IBOutlet variable thePDFView in ViewController.swift source file.

Look at the list of Received actions: these are User Actions that can be linked to IBAction functions in your source code, to perform functions such as going to the first page or last.

Now your app builds and drives and sees what difference s made. Although the size of the window has changed properly, the size of the thumbnails does not.

To fix this, you need to change the thumbnail size in the code. Quit all current copies of the app and select the file ViewController.swift . Insert the two code lines as shown.

la theSize = self.theThumbnailView.thumbnailSize
self.theThumbnailView.thumbnailSize = CGSize (width: (theSize.width * 1.1), height: (theSize.height * 1.1))
[19659002]  pdfdemo37

This first gets the current thumbnail size, like a CGSize type, and then changes the thumbnail size to 1.1 times that. This cannot show the correct scaling factor, but try it and it should show just about right.


Build and run, and continue to adjust until you have the document window the way you want it. Because there are so many reciprocal controls, you get the most important first – here, perhaps the size of thumbnails – then make final adjustments to the window and display the size to fit them well.

If you often build in Xcode 10.1, you may suddenly come across an error in the building with a red error, such as a signature problem. Don't panic: save changes and exit Xcode, reopen the project, and use the Clean Build Folder command in the Product menu to remove all old build files. This will force the next building from scratch and quite slowly, but it should not throw the same error.

It covers most of the simple customizations to the interface. There are many more features that rely on additional code, such as searching the text of a PDF document, and storing the content in rich or plain text formats. Maybe we can look at some of them next week if there is enough interest.

Source link