UIPrintPageRenderer resize footerHeight - swift4

Is it possible to change the footerHeight of some pages in the UIPrintPageRender?
Scenario: In our app we generate PDF files. An additional content came in that will be added in the footer for few pages NOT ALL. So what I did so far is to override the drawPrintFormatter(_ printFormatter: UIPrintFormatter, forPageAt pageIndex: Int)
override func drawPrintFormatter(_ printFormatter: UIPrintFormatter, forPageAt pageIndex: Int) {
footerHeight = displayRemark ? withRemarkFooterHeight : defaultFooterHeight
super.drawPrintFormatter(printFormatter, forPageAt: pageIndex)
}
I checked the footerHeight with breakpoints and I confirmed it get updated to what I want. But the PDF doesn't resize/recalculate for the said footerHeight.
Anyone able to do this?
Thanks!

Related

How to correctly scroll after item inserted into PagedListAdapter

I am using the Android Arch PagedListAdapter class. The issue I have run into is that since my app is a chat style app, I need to scroll to position 0 when an item is inserted. But the PagedListAdapter finds the diffs and calls necessary methods on the background thread so it seems that there is no dependable way to call layoutManager.scrollToPosition(0)
If anyone has any ideas on how I could scroll at the right time, it would be greatly appreciated. Thanks!
Here is my Room Dao:
#Dao
abstract class MessagesDao {
#Query("SELECT ...")
abstract fun getConversation(threadId: String): DataSource.Factory<Int, Conversation>
}
and then the LivePagedListBuilder:
LivePagedListBuilder(database.messagesDao.getConversation(threadId), PagedList.Config.Builder()
.setInitialLoadSizeHint(20)
.setPageSize(12)
.setEnablePlaceholders(true)
.build()).build()
It turns out that there is this beautiful thing called AdapterDataObsever which lets you observe the PagedListAdapter item calls. Here is how I was able to use it to solve the problem.
conversationAdapter.registerAdapterDataObserver(object : RecyclerView.AdapterDataObserver() {
override fun onItemRangeInserted(positionStart: Int, itemCount: Int) {
if (positionStart == 0) {
manager.scrollToPosition(0)
}
}
})

Xcode Markup Link Reference Within Same File

I want to make a link reference within the same file in Swift kind of like the way you can in JavaDoc, but I can't seem to find documentation describing how to do this. You can only reference external URLS. I want to be able to do something like this:
class myClass : UIView {
/// The label that displays the scale of this view
/// - seealso: [showScaleView](showScaleView())
private lazy var scaleView: UIView = UIView()
/// Shows the scale view
/// - seealso: [scaleView](scaleView)
private func showScaleView() {
...
}
}
This known issue in Xcode since Jan 2018... :(
Here is radar: https://github.com/lionheart/openradar-mirror/issues/19263

How to setup printing in cocoa, swift?

I have made printing functionality for custom NSView of NSPopover by the assigning the following action to button for this NSView in mainController:
#IBOutlet var plasmidMapIBOutlet: PlasmidMapView!
#IBAction func actionPrintfMap(sender: AnyObject)
{
plasmidMapIBOutlet.print(sender)
}
It is working, but the print window has no option for Paper Size and Orientation, see screenshot below.
What should I do to get these options in the print window?
And, how to make the NSView fitting to the printable area? Now it is not fitting.
I have figured out some moments, but not completely. So, I can setup the printing by the following code
#IBAction func actionPrintMap(sender: AnyObject)
{
let printInfo = NSPrintInfo.sharedPrintInfo()
let operation: NSPrintOperation = NSPrintOperation(view: plasmidMapIBOutlet, printInfo: printInfo)
operation.printPanel.options = NSPrintPanelOptions.ShowsPaperSize
operation.printPanel.options = NSPrintPanelOptions.ShowsOrientation
operation.runOperation()
//plasmidMapIBOutlet.print(sender)
}
But, I still have problem. From the code above I can get only orientation (the last, ShowsOrientation), but not both PaperSize and Orientation. How can I manage both ShowsPaperSize and ShowsOrientation?
Finally I have found the answer which is simple to write but it is not really obvious from apple documentation.
operation.printPanel.options.insert(NSPrintPanelOptions.showsPaperSize)
operation.printPanel.options.insert(NSPrintPanelOptions.showsOrientation)
The problem in the code originally posted is that options is being assigned twice, so the first value assigned, ShowsPaperSize is overwritten by the value ShowsOrientation. That's why you only see the ShowsOrientation option in the dialog.
By using multiple insert operations, you are adding options rather than overwriting each time. You can also do it this way which I think reads better:
operation.printPanel.options.insert([.showsPaperSize, .showsOrientation])
And finally, it also works to "set" the options, and by supplying the existing options as the first array value, you achieve the affect of appending:
operation.printPanel.options = [
operation.printPanel.options,
.showsPaperSize,
.showsOrientation
]
(The first array element operation.printPanel.options means that the old options are supplied in the list of new options.)

Backbone.Marionette overriding methods

In 0.9.3, the region manager has changed with the following entry in the changelog:
BREAKING Changed the implementation of Region to allow easier
overriding of how the new view is added to the DOM
What is the best way of overriding the open method?
Currently I am doing the following which does work but I am curious to know what the recommended way is:
_.extend(Backbone.Marionette.Region.prototype, {
open: (view) ->
#$el.after(view.el)
})
This change has also broken some code for me because in some cases I was calling show like this:
region.show(documentsView, 'after')
And in others I was calling it like this:
region.show unitsView
How can I override open to take both these instances into account or do I need to override show?
This works:
_.extend(Backbone.Marionette.Region.prototype, {
show: (view, appendMethod) ->
#ensureEl()
#close()
view.render()
#open(view, appendMethod)
#currentView = view
open: (view, appendMethod) ->
appendMethod = appendMethod || "html"
#$el[appendMethod](view.el)
})

JavaScript: Event listener on iFrame resize / height attribute change (FB comment box)

I have the following problem: I need to add an event listener for an iframe (a Facebook comment box) when it changes its height.
I can not access or change the contentWindow because it is cross domain. But there must be a callback function or something that changes the height attribute.
Is there a way to add an event listener on attribute changes or something? I alreade tried onResize and onChange.
I'm getting crazy with that... Anyone has an idea?
Thank you so much!!
Short answer: No.
However, you can use "postMessage" and "receiveMessage" to send from one iframe to another cross domain. (Of course, only if you have access to the iframed content - I suspect not as it's on facebook.)
In any case... for future help....
(on the iframed page)
var ii = {}
ii.window_height = 800;
var sendHeight = function () {
var window_height = $('body').outerHeight(true);
if (window_height != ii.window_height) {
ii.window_height = window_height;
window.parent.postMessage(ii.window_height, "http://containerDomain.com");
}
}
setInterval(sendHeight, 2000);
(on the container page)
function receiveMessage(evt) {
if (evt.origin === 'https://iframedDomain.com')
{
var iframe_content_height = evt.data;
$('#iframe_form').animate({height: iframe_content_height });
}
}
if ($.browser.msie) {
window.attachEvent('onmessage', receiveMessage);
} else {
window.addEventListener('message', receiveMessage, false);
}
Remember to change the domains in each script.
Note: that's using jQuery - It works, but I'm sure someone can write that better then me? Also not too proud of the interval checking the height... might update if i can.